C51 단편기의 타이머 학습 노트

2477 단어
 
 
/*-------------------------------------------------------*/
/* -------------author: robinson_911  -------------------------*/
/* -------------date:2014 2  -------------------------*/
/* -------------content:            -----------*/
//   22.1184MHZ ,     0, 1s        
/*-------------------------------------------------------*/
   
//#include "reg52.h"  
#include "STC_NEW_8051.H"
typedef 	unsigned char	u8;
typedef 	unsigned int	u16;
typedef 	unsigned long	u32;
 
/*************          **************/  
u16 JumpAddress,a=0;  
u8 xdata RxBuffer[64];
u8  ReCount=0, i;
u8  RxCounter=0; 

/*************	       	**************/
void push_pull();
void Serial_Initinal();
void sendchar(u8 p);
void sendstring(u8 *p);
void dmsec (u16 count);
void delay_1ms(u16 count);
void Timer0Init(void);
void Timer1Init(void);
void init() ;
 
void main()  
{
	 push_pull(); 
	 Serial_Initinal();
	 Timer0Init();
	 while(1)  
	 {  
	     i++; 
	 }  
}  


void receive(void) interrupt 4
{
  if(RI)
  {    
    RI=0;
	RxBuffer[RxCounter++]=SBUF;
  }
}

void Timer0(void) interrupt 1
{  
   	TL0 = 0x9A;		//      
	TH0 = 0xA9;		//      
	a++;
    if(a==1000)
	{
	 a=0;
     sendstring("delay 1s ");
	}

}

/*       /*/
void sendchar(u8 ch)
{
    SBUF=ch;
	while(!TI);//
	TI=0;
}
void sendstring(u8 *p)
{
   while(*p)
    { 
	 sendchar(*p++);
    }

}
/*    :      */
void dmsec (u16 count)
{
	u16 i;
	while (count)
	{
        i =230;
		while (i>0) i--;
		count--;
    }
}
/***1T     ms    ****/
void delay_1ms(u16 count)
{
    u16 i,j;
	 for(i=0;i<8*count;i++)
	{
	    for(j=0;j<225;j++){;}	    	    	   	
	}
}

void push_pull()
{
	P0M1=0X00;  //STC12C5A60s2,       
	P0M0=0XFF;
	P1M1=0X00;
	P1M0=0XFF;
	P2M1=0X00;
	P2M0=0XFF;
	P3M1=0X00;
	P3M0=0XFF;
	P4M1=0X00;
	P4M0=0XFF;
}
//   1         
void Serial_Initinal()
{
    //      
        SCON = 0x5a;        //8 bit data ,no parity bit
   	TMOD = 0x21;        //     1     2
	TH1  = TL1 = 0xfa;  //   9600
	TR1 = 1;           //T1 start running
	EA=1;
	ES=1;     
}

void Timer0Init(void)		//1  @22.1184MHz
{
        
	AUXR |= 0x80;		//     1T  
	TL0 = 0x9A;		//      
	TH0 = 0xA9;		//      
	ET0=1;
	TR0 = 1;		//   0    
}
           ,    STC_ISP    

좋은 웹페이지 즐겨찾기