8051 Atmel programming in C- Need help for one example

Status
Not open for further replies.
Why have you changed the timer reload???? 0x3cb0 will give 50mS... You are using 0xC350 which is 15mS...
 
Yes, I fix that in the meantime...
I need this
Code:
TH0=0x3C;   TL0=0xAF;
In that case I have 1 s. But problem is he put on display all numbers in 1 second . I need 1s per number . Not all..
So that is problem now..
 
I'm trying to, but I still am unsure of your problem... I posted and interrupt driven delay and an example but you choose not to use it.

Are you working with a simulator or a real device...
 
I tried with interrupt which you posted but dont work...
Thank you for that but Time TH0=0x3C; TL0=0xAF; is good for 1 s.

Problem is where put the (I think) interrupt after every number in string ...Because that is possible way to solving this problem. I dont know how to put that in code...
I can not allow to pass through all the numbers in one second.
 
I working in KEiL softwer micro vision... When I debuging softwer trow me on display one kel maket which consisting of diodes. So that is way how I tested
 
if ( (when counter decreased by one, counter is equal to zero) then decrease counter by one )

So if counter was 1.... "a-1;" is executed bu then counter is decreased again so counter = -1

If counter = 2.... You'll miss it..

BTW... my code does work!!! I tried it here before I sent it!!
 
Hi, I solved problem with displaying number per second. But now I have problem with displaying numbers with four string...
He always recognizing only one string in interrupt rutin. Probably I need something between strings in interrupt rutine .. But I dont know what..
So program check only one string, another doesnt exist. He must check all string but I dont know how

NEED HELP

Code:
#include <reg51.h>
#include <math.h>
typedef unsigned char byte;

byte a[16]={1,22,31,4,5,6,7,8,23,3,10,30,73,40,55,93};
byte b[16]={3,14,7,13,17,19,97,1,12,128,127,124,123,122,33,21};
byte c[16]={9,15,4,13,41,49,57,18,74,3,39,59,112,100,91};
byte d[16]={33,58,68,66,21,19,97,1,14,222,56,12,3,9,15,11};

sbit switcher=P0^0;
byte i=0;
byte counter;


byte xdata display _at_ 0x8001;
void Inic(void) {
   EA=1;
   ET0=1;
   TMOD=0x01;
   TH0=0xC3;
   TL0=0x50;
   TR0=1;
   counter=0;
   i=0;

}

void timer0 (void) interrupt 1 using 2 {
   
   TH0=0xC3;
   TL0=0x50;
   
if((++counter==0)) {    counter=20;
   if(switcher) {
   
   if(!(a[i]%3) )
     display = a[i];

     i++;
     if(i==16) i=0;
      if(!(b[i]%3) )
       display = b[i];

     i++;
     if(i==16) i=0;
       if(!(c[i]%3) )
       display = c[i];

     i++;
     if(i==16) i=0;
       if(!(d[i]%3) )
       display = d[i];

     i++;
     if(i==16) i=0;
   }}
   TR0=0;
}

void main(void) {
   Inic();
   while(1){TR0=1;}
   }
 
Hi,
Your code must be as this

#include <reg51.h>
#include <math.h>

typedef unsigned char byte;

byte a[3]= {2,1,8};

byte counter, frequency,displ;

int i=0;

byte xdata display _at_ 0x8001;

sbit switcher=P0^0;

void Inic(void)
{
ET0=1;
TMOD=1;
TH0=0x3C;
TL0=0xB0;
TR0=1;
counter=1;
frequency=0;
}

void timer0(void) interrupt 1 using 2
{
TR0=0;
TH0=0x3C;
TL0=0xB0;
TR0=1;
if(switcher)
{
if(!(--counter))
{
counter=frequency;
display=displ;
}
}
}

void main(void)
{
Inic();
EA=1; // It is good to enable goble interrupt in the main

while(1)
{
if(switcher)
{
for (i=0;i<3;i++)
{
if((a)/2) // " a/2 what is this? You con't pass an array to it,
//pass only array elements as this a
//if you use (a/2) compiler gives Error C:193
//"Bad Operand Type"?"
//This error results when an expression uses
//illegal operand types with the given operator.
//Examples of invalid expressions are
//bit * bit, ptr + ptr, or ptr * anything.
{
displ=a;
frequency=20;
}
}
}
}
}
 

Attachments

  • test.c
    1.3 KB · Views: 399
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…