stc52rc单片机点亮LCD1602程序如附件。显示时钟。
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uint dxf[8]; //定义一个数组,用于显示秒高低位、 分高低位、 时高低位及冒号
- uint num1,num2,num3,num4,num5,num6,count1; //count1用于中断50MS时间到判断
- uint fk0,fk1,fk2,fk3,fk4,fk5,fk6,fk7,ab1,ab2,ab3,ab4,ab5,ab6;
- sbit LCDEn=P0^2;
- sbit RS11=P0^0;
- sbit rw=P0^1;
- unsigned char code table[]={"HELLO 2015 "};
- unsigned char code table1[]={"hello world: "};
- unsigned char code tab12[]={'0','1','2','3','4','5','6','7','8','9'}; //用于液晶显示调用
- unsigned char code tab13[]={":"} ;
- unsigned char code tab11[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//用于数码显示调用
- void delay2(num2) //长延时
- {
- uchar aa1;
- for(;num2>0;num2--)
- for(aa1=120;aa1>0;aa1--)
- {;}
- }
- void T01() interrupt 1 /*****定时器T0中断子程序*****/
- {
- count1++ ;
- if(count1==4)
- {
- num4++;
- count1=0;
- }
-
- TH0=(65535-50000)/256; /*******50ms定时器,高八位******/
- TL0= (65535-50000)%256;
- }
- void delay(unsigned int m )
- {
- unsigned char n; /****局部定义**/
- for(;m>1;m--)
- for(n=60;n>0;n--)
- ;
- }
- void okplay( )// 开显示
- {
- uchar aa2;
- for(aa2=1;aa2<9;aa2++)
- {
- if(num4==60)
- {
- num5++;
- if(num5==60)
- {
- num6++;
- if(num6==24)
- {
- num6=0;
- }
- num5=0;
- }
- num4=0;
- }
- switch(aa2)
- {
- case 1: dxf[0]=num6/10; break;
- case 2: dxf[1]=num6%10; break;
- case 3: dxf[2]=0[tab13] ; break;
- case 4: dxf[3]=num5/10; break;
- case 5: dxf[4]=num5%10; break;
- case 6: dxf[5]=0[tab13] ; break;
- case 7: dxf[6]=num4/10; break;
- case 8: dxf[7]=num4%10; P1=dxf[7][tab11]; P3=0X20; break;
- }
- }
- }
- void lowcom(unsigned char a) /****写命令**/
- {
- LCDEn=0;
- RS11=0;
- rw=0;
- P2=a;
- delay(2);
- LCDEn=1;
- delay(2);
- LCDEn=0;
- }
- void lowwrite(uchar ab) /****写数据**/
- {
- LCDEn=0;
- RS11=1;
- rw=0;
- P2=ab;
- delay(2);
- LCDEn=1;
- delay(2);
- LCDEn=0;
- }
- /********初始化程序********/
- void invion()
- {
- lowcom(0x38); /****开显示**/
- delay(2);
- lowcom(0x0f); /****初始化**/
- delay(2);
- lowcom(0x06); /***写一个指针数加1**/
- delay(2);
- lowcom(0x0C);/****开显示不显光标**/
- delay(2);
- }
- void main()
- {
- unsigned char xx1,xx2;
- TMOD=0X01;
- TH0=(65535-50000)/256; /*******5ms定时器,高八位******/
- TL0= (65535-50000)%256;
- EA=1; /******开总中断******/
- ET0=1;/******允许T0中断******/
- TR0=1; /*******T0中断开始******/
- invion(); /****初始化**/
- while(1)
- {
- okplay();
- lowcom(0x80);/****显示第一行从第1 位开始显示**/
- for(xx1=0;xx1<8;xx1++)
- {
- //原显示lowwrite( dxf[xx1][tab12]),因冒号无法显示改为switch语句
-
- switch(xx1)
- {
- case 0:lowwrite( dxf[xx1][tab12]); break ;
- case 1: lowwrite(dxf[xx1][tab12]); break;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
LCD_1.zip
(38.98 KB, 下载次数: 16)
|