|
附件内有上位机VB源码和上位机安装程序,图片左上角的小界面是上位机程序,可获取电脑的时间和日期发送到16*64LED上显示(需要安装虚拟串口)。
单片机16*64LED条屏仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include "reg51.h" //包含51单片机的端口和内部寄存器定义的头文件
- typedef unsigned char uint8; //定义字符型
- typedef unsigned int uint16; //定义整型
- typedef unsigned long uint32; //定义长整型
- uint32 dx,dxx; //字符显示偏移量
- uint8 brk,flag;
- uint8 BUFFER[22];
- sbit RTC_RST = P3^5;
- sbit RTC_SCLK = P3^6;
- sbit RTC_IO = P3^7;
- uint8 bdata AA; //brk延时用
- uint8 const code dat_bit_up[]={0xF7,0xFB,0xFD,0xFE,0x7F,0xBF,0xDF,0xEF}; //列高位扫描数据
- uint8 const code dat_bit_down[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; //列低位扫描数据
- sbit AA7 = AA^7;
- #define READ_SECOND 0x81
- #define WRITE_SECOND 0x80
- #define READ_MINE 0x83
- #define WRITE_MINE 0x82
- #define READ_HOUR 0x85
- #define WRITE_HOUR 0x84
- #define READ_DAY 0x87
- #define WRITE_DAY 0x86
- #define READ_MONTH 0x89
- #define WRITE_MONTH 0x88
- #define READ_WEEK 0x8b
- #define WRITE_WEEK 0x8a
- #define READ_YEAR 0x8d
- #define WRITE_YEAR 0x8c
- uint8 const code NUM[][16]=
- {
- {0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,0x00},/*"0",0*/
- …………
- …………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- {0x00,0x00,0x10,0x81,0x28,0xC2,0x21,0x44,0x21,0x24,0x22,0x00,0x3E,0xFF,0x22,0x44,0x22,0x44,0x22,0x7C,0x3E,0x44,0x22,0x7C,0x22,0x44,0x22,0xFE,0x3E,0x44,0x00,0x44},/*"期",4*/
- {0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00},/*":",0*/
- };
- /*****************************************************************************************************************************
- / 端口定义
- ******************************************************************************************************************************/
- #define LED_PORTH P0 //列高位
- #define LED_PORTL P2 //列低位
- sbit SER_CP=P3^4; //串行时钟线
- sbit SER_SDA=P3^3; //串行数据线
- sbit SER_EN=P3^2; //74595数据有效线
- /*****************************************************************************************************************************
- / 函数名称:Delay
- / 作用: 延时子程序主要用于LED的消隐
- ******************************************************************************************************************************/
- void Delay() //延时子程序
- {
- uint16 i,j;
- for(i=0;i<0x14;i++)
- for(j=0;j<0x05;j++);
- }
- /*****************************************************************************************************************************
- / 函数名称:LED_Ser
- / 作用: 发送串行数据到74LS595
- / 入口参数:dat 为要发送的数据8位
- ******************************************************************************************************************************/
- void LED_Ser(uint16 dat)
- {
- uint8 i;
- for(i=0;i<16;i++) //共8BYTE
- {
- SER_SDA=dat&0x01; //把数据的最后一位放在数据线上
- dat>>=1; //向右移位共8下这样可以发送8位数据
- SER_CP=0; //
- SER_CP=1; //产生上升沿发送数据1BYTE
- }
- }
- void LED_Ser_8(uint8 dat)
- {
- uint8 i;
- for(i=0;i<8;i++) //共8BYTE
- {
- SER_SDA=dat&0x01; //把数据的最后一位放在数据线上
- dat>>=1; //向右移位共8下这样可以发送8位数据
- SER_CP=0; //
- SER_CP=1; //产生上升沿发送数据1BYTE
- }
- }
- /*****************************************************************************************************************************
- / 函数名称:LED_Ser_EN
- / 作用: 用于在SER_EN口线上产生上长沿使74595发送的数据有效
- ******************************************************************************************************************************/
- void LED_Ser_EN()
- {
- SER_EN=0; //
- SER_EN=1; //产生上升沿脉冲用于使74595发的数据有效
- }
- /*****************************************************************************************************************************
- / 函数名称:LED_Disp
- / 作用: 在LED上显示字符或BMP
- / 入口参数:*dat 为要显示的字符或BMP的数据的首地址指针
- ******************************************************************************************************************************/
- void LED_Disp(uint16 *dat)
- {
- uint16 tmp;
- uint8 a,j,i;
- for(j=0;j<16;)
- {
- for(i=0;i<16;i++)
- {
- for(a=0;a<4;a++) //共四个字
- {
- if(dx>15){dxx+=16;dx=0;} //dx,dxx为显示偏移量
- tmp=((dat[i+dxx+a*16]>>dx)|(dat[i+dxx+(a+1)*16]<<(16-dx)));//移动一位最大可移动八位左
- if(dat[i+(a+1)*16+dxx]==0x55aa){dxx=0;tmp=0;flag=1;}
- LED_Ser(~tmp); //发送右
- }
- LED_Ser_EN(); //使发送的数据显示
- if(j<8){LED_PORTH=dat_bit_up[j];LED_PORTL=0XFF;} //上半列扫描
- else{LED_PORTL=dat_bit_down[j-8];LED_PORTH=0XFF;} //下半列扫描
- Delay(); //延时
- LED_PORTL=0XFF; //消隐
- LED_PORTH=0XFF; //消隐
- j++;
- }
- }
- }
- void RTC_Write(uint8 dat)
- {
- uint8 i;
- for(i=0;i<8;i++)
- {
- RTC_IO=(bit)(dat&0x01);
- RTC_SCLK=1;
- RTC_SCLK=0;
- dat>>=1;
- }
- }
- uint8 RTC_Read()
- {
- uint8 i;
- for(i=0; i<8; i++)
- {
- AA >>=1; //相当于汇编中的 RRC
- AA7 = RTC_IO;
- RTC_SCLK = 1;
- RTC_SCLK = 0;
- }
- return AA;
- }
- void RTC_Write_Byte(uint8 addr,uint8 dat)
- {
- RTC_RST=0;
- RTC_SCLK=0;
- RTC_RST=1;
- RTC_Write(addr);
- RTC_Write(dat);
- RTC_SCLK=1;
- RTC_RST=0;
- }
- uint8 RTC_Read_Byte(uint8 addr)
- {
- uint8 dat;
- RTC_RST=0;
- RTC_SCLK=0;
- RTC_RST=1;
- RTC_Write(addr|0x01);
- dat=RTC_Read();
- RTC_SCLK=1;
- RTC_RST=0;
- return dat;
- }
- typedef struct __SYSTEMTIME__
- {
- uint8 Second;
- uint8 Mine;
- uint8 Hour;
- uint8 Day;
- uint8 Month;
- uint8 Week;
- uint8 Year;
- }SYSTEMTIME;
- SYSTEMTIME TIMETYPE;
- void CurrentTime(SYSTEMTIME *dat)
- {
- uint8 TimeValue;
- TimeValue=RTC_Read_Byte(READ_SECOND);
- dat->Second=(((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_MINE);
- dat->Mine= (((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_HOUR);
- dat->Hour= (((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_DAY);
- dat->Day= (((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_MONTH);
- dat->Month= (((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_WEEK);
- dat->Week= (TimeValue&0x0f);
- TimeValue=RTC_Read_Byte(READ_YEAR);
- dat->Year= (((TimeValue&0x70)>>4)*10)+(TimeValue&0x0f);
- }
- void LED_Disp_Time_Year(SYSTEMTIME *dat)
- {
- uint8 j,i;
- for(j=0;j<16;)
- {
- for(i=0;i<16;i++)
- {
- LED_Ser_8(~HZ[0][i]); //发送右
- LED_Ser_8(~NUM[2][i]); //发送右
- LED_Ser_8(~NUM[0][i]); //发送右
- LED_Ser_8(~NUM[(dat->Year)/10][i]); //发送右
- LED_Ser_8(~NUM[(dat->Year)%10][i]); //发送右
- LED_Ser_8(~Date[0][i*2+1]);
- LED_Ser_8(~Date[0][i*2]);
- LED_Ser_8(~HZ[0][i]); //发送右
-
- LED_Ser_EN(); //使发送的数据显示
- if(j<8){LED_PORTH=dat_bit_up[j];LED_PORTL=0XFF;} //上半列扫描
- else{LED_PORTL=dat_bit_down[j-8];LED_PORTH=0XFF;} //下半列扫描
- Delay(); //延时
- LED_PORTL=0XFF; //消隐
- LED_PORTH=0XFF; //消隐
- j++;
- }
- }
- }
- void LED_Disp_Time_Month(SYSTEMTIME *dat)
- {
- uint8 j,i;
- for(j=0;j<16;)
- {
- for(i=0;i<16;i++)
- {
- LED_Ser_8(~NUM[dat->Month/10][i]); //发送右
- LED_Ser_8(~NUM[dat->Month%10][i]); //发送右
- LED_Ser_8(~Date[1][i*2+1]); //发送右
- LED_Ser_8(~Date[1][i*2]); //发送右
- LED_Ser_8(~NUM[dat->Day/10][i]); //发送右
- LED_Ser_8(~NUM[dat->Day%10][i]);
- LED_Ser_8(~Date[2][i*2+1]);
- LED_Ser_8(~Date[2][i*2]); //发送右
-
- LED_Ser_EN(); //使发送的数据显示
- if(j<8){LED_PORTH=dat_bit_up[j];LED_PORTL=0XFF;} //上半列扫描
- else{LED_PORTL=dat_bit_down[j-8];LED_PORTH=0XFF;} //下半列扫描
- Delay(); //延时
- LED_PORTL=0XFF; //消隐
- LED_PORTH=0XFF; //消隐
- j++;
- }
- }
- }
- void LED_Disp_Time_Week(SYSTEMTIME *dat)
- {
- uint8 j,i;
- for(j=0;j<16;)
- {
- for(i=0;i<16;i++)
- {
- LED_Ser_8(~HZ[0][i]); //发送右
- LED_Ser_8(~Date[3][i*2+1]); //发送右
- LED_Ser_8(~Date[3][i*2]); //发送右
- LED_Ser_8(~Date[4][i*2+1]); //发送右
- LED_Ser_8(~Date[4][i*2]); //发送右
- LED_Ser_8(~WEEK[dat->Week-1][i*2+1]);
- LED_Ser_8(~WEEK[dat->Week-1][i*2]);
- LED_Ser_8(~HZ[0][i]); //发送右
-
- LED_Ser_EN(); //使发送的数据显示
- if(j<8){LED_PORTH=dat_bit_up[j];LED_PORTL=0XFF;} //上半列扫描
- else{LED_PORTL=dat_bit_down[j-8];LED_PORTH=0XFF;} //下半列扫描
- Delay(); //延时
- LED_PORTL=0XFF; //消隐
- LED_PORTH=0XFF; //消隐
- j++;
- }
- }
- }
- void LED_Disp_Time_Time(SYSTEMTIME *dat)
- {
- uint8 j,i;
- for(j=0;j<16;)
- {
- for(i=0;i<16;i++)
- {
- LED_Ser_8(~NUM[dat->Hour/10][i]); //发送右
- LED_Ser_8(~NUM[dat->Hour%10][i]); //发送右
- LED_Ser_8(~Date[5][i]); //发送右
- LED_Ser_8(~NUM[dat->Mine/10][i]); //发送右
- LED_Ser_8(~NUM[dat->Mine%10][i]); //发送右
- LED_Ser_8(~Date[5][i]);
- LED_Ser_8(~NUM[dat->Second/10][i]);
- LED_Ser_8(~NUM[dat->Second%10][i]); //发送右
-
- LED_Ser_EN(); //使发送的数据显示
- if(j<8){LED_PORTH=dat_bit_up[j];LED_PORTL=0XFF;} //上半列扫描
- else{LED_PORTL=dat_bit_down[j-8];LED_PORTH=0XFF;} //下半列扫描
- Delay(); //延时
- LED_PORTL=0XFF; //消隐
- LED_PORTH=0XFF; //消隐
- j++;
- }
- }
- }
- /*****************************************************************************************************************************
- / 函数名称:ET0_INT
- / 作用: 定时器T0的中断服务程序用于延自加字符显示偏移量以产生字符滚动显示的效果
- ******************************************************************************************************************************/
- void ET0_INT() interrupt 1 using 0 //中断服务程序
- {
- TH0=0x03;
- TL0=0x04;
- brk++;
- if(brk==10)
- {
- brk=0; //brk延时用
- dx++; //字符显示偏移量
- }
- }
- void Char_to_time(uint8 *dat)
- {
- uint8 year,month,day,week,hour,mine;
- year=((dat[0]-'0')*16+(dat[1]-'0'));
- month=((dat[3]-'0')*16+(dat[4]-'0'));
- day=((dat[6]-'0')*16+(dat[7]-'0'));
- hour=((dat[9]-'0')*16+(dat[10]-'0'));
- mine=((dat[12]-'0')*16+(dat[13]-'0'));
- week=(dat[15]-'0');
- RTC_Write_Byte(0x8e,0x00); //写入允许
- RTC_Write_Byte(0x80,WRITE_SECOND|0x80);
- RTC_Write_Byte(0x8e,0x80); //禁止写入
- RTC_Write_Byte(0x8e,0x00); //写入允许
- RTC_Write_Byte(WRITE_YEAR,year); //写入新的秒数
- RTC_Write_Byte(WRITE_MONTH,month); //写入新的秒数
- RTC_Write_Byte(WRITE_DAY,day); //写入新的秒数
- RTC_Write_Byte(WRITE_HOUR,hour); //写入新的秒数
- RTC_Write_Byte(WRITE_MINE,mine&0x7f); //写入新的秒数
- RTC_Write_Byte(WRITE_WEEK,week); //写入新的秒数
- RTC_Write_Byte(0x8e,0x00); //写入允许
- RTC_Write_Byte(0x80,WRITE_SECOND&0x7f);
- RTC_Write_Byte(0x8E,0x80);
- }
-
- void Serial_int() interrupt 4 using 0
- {
- uint8 i;
- for(i=0;i<17;i++)
- {
- // RI=0;
- while(RI==0);
- RI=0;
- BUFFER[i]=SBUF;
- }
- Char_to_time(BUFFER);
- }
- /*****************************************************************************************************************************
- / 函数名称:main
- / 作用: 主程序
- ******************************************************************************************************************************/
- void main()
- {
- // TMOD=0x01; //定时器方式1
- TH0=0x03;
- TL0=0x04;
-
- TMOD=0x20;
- TH1=0xfd;
- TL1=0xfd;
- SCON=0x50;
- PCON&=0xef;
- EA=1; //开总中断
- ET0=1; //开定时器中断
- TR0=1; //开始定时
- ES=1;
- TR1=1;
- RI=0;
- while(1)
- {
-
- while(!flag)
- {
- LED_Disp(HZ);
- }
- while(dx!=0x14)
- {
- CurrentTime(&TIMETYPE);
- LED_Disp_Time_Year(&TIMETYPE); //显示主程序
- }
- dx=0;
- while(dx!=0x14)
- {
- CurrentTime(&TIMETYPE);
- LED_Disp_Time_Month(&TIMETYPE);
- }
- dx=0;
- while(dx!=0x14)
- {
- CurrentTime(&TIMETYPE);
- LED_Disp_Time_Week(&TIMETYPE);
- }
- dx=0;
- while(dx!=0x6f)
- {
- CurrentTime(&TIMETYPE);
- LED_Disp_Time_Time(&TIMETYPE);
- }
- dx=0;
- flag=0;
- while(!flag)
- {
- LED_Disp(HZ1);
- }
- flag=0;
- }
-
- }
复制代码
所有资料51hei提供下载:
HBLED.rar
(3.53 MB, 下载次数: 47)
|
评分
-
查看全部评分
|