單片機做的心形燈,同時在16*16點陣上顯示生日快樂和笑臉圖片,下面是仿真原理圖:
0.png (41.64 KB, 下載次數: 70)
下載附件
2016-10-25 14:09 上傳
單片機源程序:
- #include <at89x51.h>
- #include <DS1302.h>
- #define din P3_2
- #define load P3_3
- #define clk P3_4
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char code dispcode[]={0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x01};
- uchar buf[]={0,0,0,0,0,0,0,0};
- SYSTEMTIME time1;
- unsigned char code tab1[]={
- 0x0F,0x00,0x1F,0x80,0x3F,0xC0,0x7F,0xE0,
- 0x7F,0xF0,0x7F,0xF8,0x3F,0xFC,0x1F,0xFE,
- 0x1F,0xFE,0x3F,0xFC,0x7F,0xF8,0x7F,0xF0,
- 0x7F,0xE0,0x3F,0xC0,0x1F,0x80,0x0F,0x00,//心型圖
-
- 0x00,0x80,0x01,0x02,0x06,0x02,0x78,0x82,
- 0x08,0x82,0x08,0x82,0x08,0x82,0x08,0x82,
- 0xFF,0xFE,0x48,0x82,0x08,0x82,0x08,0x82,
- 0x19,0x82,0x08,0x86,0x00,0x02,0x00,0x00,/*"生",2*/
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFC,
- 0x42,0x08,0x42,0x08,0x42,0x08,0x42,0x08,
- 0x42,0x08,0x42,0x08,0x42,0x08,0x7F,0xFC,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"日",3*/
-
- 0x0E,0x00,0x00,0x00,0xFF,0xFF,0x10,0x00,
- 0x0D,0x01,0x11,0x02,0x11,0x0C,0x11,0x70,
- 0xFF,0x80,0x11,0x60,0x11,0x10,0x11,0x0C,
- 0x1F,0x06,0x01,0x03,0x01,0x02,0x00,0x00,/*"快",4*/
-
- 0x00,0x00,0x00,0x04,0x02,0x18,0x3F,0x30,
- 0x22,0xE0,0x22,0x48,0x22,0x04,0x62,0x02,
- 0x5F,0xFC,0x42,0x00,0xC2,0x00,0xC2,0x40,
- 0x42,0x30,0x02,0x1C,0x00,0x08,0x00,0x00,/*"樂",5*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x3F,0x8C,0x7F,0xDE,
- 0x7F,0xDE,0x3F,0x8C,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!
- 0x00,0x00,0x42,0xFE,0x42,0x02,0x7E,0x00,
- 0x42,0xFE,0x42,0x82,0x00,0xFE,0x00,0x00,
- 0x00,0xFC,0x00,0x02,0x7E,0xFC,0x02,0x00,
- 0x02,0xFE,0x02,0x92,0x7E,0x92,0x00,0x00,//I LOVE U
- 0xE0,0x07,0x8F,0xF1,0x98,0x19,0x30,0x0C,
- 0x64,0x46,0x48,0x22,0x44,0x12,0x40,0x12,
- 0x40,0x12,0x44,0x12,0x48,0x22,0x64,0x46,
- 0x30,0x0C,0x98,0x19,0x8F,0xF1,0xE0,0x07,//笑臉
- };
- unsigned char code tab2[]={ 0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,
- 0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
- uchar code tab3[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x03,0x06,
- 0x0c,0x18,0x30,0x60,0xe0,0x70,0x38,0x1c,0x0e,0x07,
- 0x0f,0x1f,0x3e,0x7c,0xf8,0xfc,0x7e,0x3f,0x7f,0xfe,
- 0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x3f,
- 0x9f,0xcf,0xe7,0xf3,0xf9,0xfc,0xf8,0xf1,0xe3,0xc7,
- 0x8f,0x1f,0x0f,0x87,0xc3,0xe1,0xf0,0xe0,0xc1,0x83,
- 0x07,0x03,0x81,0xc0,0x80,0x01,0x00,
- 0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00,0x01,0x03,
- 0x07,0x0f,0x1f,0x3f,0x7f,0xff,0xe7,0xc3,0x81,0x00,
- 0x81,0xc3,0xe7,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,
- 0xbf,0x7f,0x7e,0x7d,0x7b,0x77,0x6f,0x5f,0x3f,0x3e,
- 0x3d,0x3b,0x37,0x2f,0x1f,0x1e,0x1d,0x1b,0x17,0x0f,
- 0x0e,0x0d,0x0b,0x07,0x06,0x05,0x03,0x02,0x01,0x00,
- 0x55,0xaa,0x55,0xaa,0x00,0xff,0x00,0xff,0x00,0xff,};
- sbit KAI=P1^4;
- sbit KAI2=P1^5;
- void delay(uint time);
- uint j=0,q=0;
- uchar r,t=0,num=0;
- void csh()
- {
- load=1;
- clk=1;
- din=1;
- }
- Delayms(uint c)
- {
- uint a,b;
- for(a=0;a<c;a++)
- for(b=0;b<120;b++);
- }
- void write(uchar com,uchar da)
- {
- uchar temp,i,j;
- load=0;
- clk=0;
- for(i=0;i<8;i++)
- { temp=com;
- if((temp&(0x80>>i))!=0)
- din=1;
- else din=0;
- clk=1;
- for(j=0;j<5;j++);
- clk=0;
- }
- for(i=0;i<8;i++)
- { temp=da;
- if((temp&(0x80>>i))!=0)
- din=1;
- else din=0;
- clk=1;
- for(j=0;j<5;j++);
- clk=0;
- }
- load=1;
- }
- void main()
- {
-
- csh();
- write(0x0c,0x01);//正常工作狀態,關斷模式
- write(0x09,0x00);//譯碼選擇,非BCD碼
- write(0x0a,0x0a);//亮度調節
- write(0x0b,0x07);//顯示位數
- Initial_DS1302();
- while(1)
- {
- DS1302_GetTime(&time1);
- buf[7]=(time1.Second)%10;
- buf[6]=(time1.Second)/10;
- buf[4]=(time1.Minute)%10;
- buf[3]=(time1.Minute)/10;
- buf[1]=(time1.Hour)%10;
- buf[0]=(time1.Hour)/10;
- write(0x08,dispcode[buf[7]]);
- write(0x07,dispcode[buf[6]]);
- write(0x06,dispcode[10]);
- write(0x05,dispcode[buf[4]]);
- write(0x04,dispcode[buf[3]]);
- write(0x03,dispcode[10]);
- write(0x02,dispcode[buf[1]]);
- write(0x01,dispcode[buf[0]]);
- // Delayms(200);
- num++;
- if(num==137)
- num=0;
- for(r=0;r<105;r++)
- for(j=q;j<32+q;j++)
- {
- P1=tab2[t];
- KAI=1;
- P2=0X00;
- P2=tab1[j];
- KAI=0;
- j++;
- KAI2=1;
- P2=0X00;
- P2=tab1[j];
- KAI2=0;
- P0=tab3[num];
- delay(40);
- t++;
- if(t==16)
- t=0;
- }
- q=q+32;
- if(q==256)
- q=0;
- }
- }
- void delay(uint time)
- {
- uint linger;
- for(linger=0;linger<time;linger++);
- }
復制代碼
0.png (67.43 KB, 下載次數: 70)
下載附件
2016-10-25 14:12 上傳
所有資料打包下載:
生日禮物心形燈仿真帶時間顯示.rar
(29.23 KB, 下載次數: 50)
2016-10-25 14:12 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|