cc2530显示时间
只给出了显示时间部分的代码,lcd.h没有给出,可以用之前的lcd.h,内容一致的 包括中断、定时器、串口收发
#include <iocc2530.h>
#include "LCD.h"
#define rled P1_0
#define gled P1_1
void initio(void)
{
P1SEL &=0XFC;
P1DIR|=0X03;
rled=0;
gled=0;
}
void initclock(void)
{
CLKCONCMD &=0XBF;
CLKCONCMD |=0X28;
CLKCONCMD &=0XEF;
while(CLKCONSTA & 0X40);
}
void initt3(void)
{
T3CCTL0 |=0X04;
T3CCTL0 |=0X40;
T3CC0=0XFA;
T3CTL |=0X80;
T3CTL &=0X9A;
T3CTL |=0X02;
T3CTL &=0XFE;
T3CTL |=0X08;
IEN1 |=0X08;
IEN0 |=0X80;
T3CTL |=0X10;
}
void inituart0(void)
{
PERCFG &=0XFE;
P0SEL |=0X3C;
P2DIR &=0X3F;
PERCFG = 0x00;
U0CSR |=0X80;
U0GCR |=8;
U0BAUD |=59;
UTX0IF=0;
U0CSR |=0X40;
IEN0 |=0X04;
IEN0 |=0X80;
}
void uarttx_send_string(unsigned char *data,int len)
{
int j;
for(j=0;j<len;j++)
{
U0DBUF=*data++;
while(UTX0IF==0);
UTX0IF=0;
}
}
unsigned char time[3]={01,01,01};
unsigned char recdata[10];
unsigned char senddata[15]="00:00:00 ";
unsigned char timetemp;
unsigned char counter=0;
unsigned char temp;
unsigned char number=0;
unsigned char follow_second;
void main(void)
{
initclock();
initt3();
inituart0();
initio();
LCD_Init();
LCD_CLS();
LCD_welcome();
uarttx_send_string(senddata,8);
do{
if(timetemp==1)
{
if(time[2]<59)
{
time[2]++;
}
else
{
time[2]=0;
if(time[1]<59)
{
time[1]++;
}
else
{
time[1]=0;
if(time[0]<23)
{
time[0]++;
}
else
{
time[0]=0;
}
}
}
timetemp=0;
}
if(temp!=0)
{
if((temp!='*')&&(number<10))
{
recdata[number++]=temp;
}
temp=0;
}
if((recdata[0]=='#')&&(number==9))
{
time[2]= (recdata[7]-48)*10+(recdata[8]-48);
if(time[2]>59)
time[2]=0;
time[1]=(recdata[4]-48)*10+(recdata[5]-48);
if(time[1]>59)
time[1]=0;
time[0]=(recdata[1]-48)*10+(recdata[2]-48);
if(time[0]>23)
time[0]=0;
gled=!gled;
recdata[0]=0;
number=0;
}
if(follow_second!=time[2])
{
senddata[7]=(char)(time[2])%10+'0';
senddata[6]=(char)(time[2])/10+'0';
senddata[4]=(char)(time[1])%10+'0';
senddata[3]=(char)(time[1])/10+'0';
senddata[1]=(char)(time[0])%10+'0';
senddata[0]=(char)(time[0])/10+'0';
LCD_P8x16Str(32,6,senddata);
uarttx_send_string(senddata,8);
uarttx_send_string("\r\n",2);
follow_second=time[2];
}
}while(1);
}
#pragma vector=T3_VECTOR
__interrupt void T3_ISR(void)
{
IRCON &=0XF7;
counter++;
if(counter==250)
{
counter=0;
timetemp=1;
rled=!rled;
}
}
#pragma vector=URX0_VECTOR
__interrupt void UART0_ISR(void)
{
URX0IF=0;
temp=U0DBUF;
}
|