N N 外中断1 Y 流水灯循环点亮 LCD显示 4.2程序清单
#include
#define uchar unsigned char #define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar temp;
uint count=0,ff=0,aa=0; uint j,flag;
sbit RS=P1^6; sbit RW=P1^7; sbit E=P1^5; sbit P32=P3^2; sbit P33=P3^3; sbit P34=P3^4; sbit P35=P3^5;
void init();
void writestr(char *str); void writechar(uchar ch); void write_com(uchar cmd); void delay(uchar z);
void main() { w=0; P0=table[0]; TMOD=0x16; TH1=(65536-50000)/256; TL1=(65536-50000)%6;
12
TH0=TL0=0xff; EA=1; EX0=1; //外部中断0 IT0=1; EX1=1; //外部中断1 IT1=1; PX1=1; PT0=1; ET0=1; //定时0 TR0=1; ET1=1; //启动定时1 while(1) { if(P35==0) TR1=1; if(flag) { flag=0; aa++; if(aa==60) aa=0; w=0; P0=table[aa/10]; E=1; P2=0x00; P0=table[aa]; } } }
void led() interrupt 0 {
// uint j;
// uchar temp; while(1) { temp=0xfe; for(j=0;j<=7;j++)
13
{ P2=temp; delay(100); temp=_crol_(temp,1); } if((P34==0)||(P35==0)) break; temp=0x7f; for(j=0;j<=7;j++) { P2=temp; delay(100); temp=cror_(temp,1); } if((P34==0)||(P35==0)) break; } }
void lcd() interrupt 2 { init(); write_com(0x80); writestr(\ write_com(0xc0); writestr(\ delay(100); write_com(0x01); write_com(0x80); writestr(\ write_com(0xc0); writestr(\ delay(100); write_com(0x01); write_com(0x80); writestr(\ ***\ write_com(0xc0); writestr(\ delay(100); write_com(0x01); }
void sum() interrupt 1 { TR1=0;
14
P2=0x00; if(P34==0) count++; if(count==100) count=0; E=0; P0=table[count/10]; E=1; P2=0x00; P0=table[count]; }
void dingshi() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%6; ff++; if(ff==20) { ff=0; flag=1; } } void delay(uchar z) { uchar i,j; for(i=z;i>0;i++) for(j=110;j>0;j++); } /*
bit LCD_Busy() { bit result; RS=0; RW=1; P2=0x40; E=1; delay(1); result=(bit)(P0&0x80); E=0; return(result); } */
void write_com(uchar cmd)
15