EmbDev.net

Forum: µC & Digital Electronics ATMEL 8051 programming in C, example


Author: Mike Man (8051help)
Posted on:

Rate this post
0 useful
not useful
I need to write only numbers (every second) in string on display (memory 
mapped on 0x8001 adress) which are divding with 3 .

I must use counter not delay () for interrupt ...

I got with code below only to printing all numbers in one second.
I need 1 number per second, not all.

Anybody help?

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

byte a[8]= {7,5,16,3,1,4,11,9}; 

byte counter;
byte xdata display _at_ 0x8001;
byte started = 0;
int i=0;

sbit switcher=P0^0;
 
void Inic(void) 
{
    EA=1;         
    TMOD=1;       
    TH0=0x3C;     
    TL0=0xAF;    
    TR0=1;
    counter=1;    
}

 
void timer0(void) interrupt 1 using 2 
{    
    TH0=0x3C;  
    TL0=0xAF;                
    
  counter--; 
    if(counter == 0)         
          {
            counter = 20;        
       if(started == 1)  
         {
         if(i < 8)              
            if(!(a[i]%3) )       
               display=a[i];                            
         i++;             
         if(i == 8)                            
            {
            ET0 = 0;      
            TR0 = 0;     
            started = 0;  
            }
         }
    }   
}

void main(void) 
{
   Inic();        
   switcher = 1;  
   while(1)       
     {                    
     if(switcher == 0)    
       if(started == 0)   
          {         
          started = 1;    
          i = 0;          
          counter = 20;    
                         
          TH0=0x3C;       
          TL0=0xAF;      
          ET0=1;        
          TR0=1;            
          }
     }            
} 


Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.