单片机源程序如下:
- #include<reg51.h>
- #include<intrins.h>
- sbit E=P3^0;
- sbit RW=P3^1;
- sbit DI=P3^2;
- sbit CS2=P3^3;
- sbit CS1=P3^4;
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char cons,cont;
- uchar code
- shuzi[16][32]={{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"0",0*/
- {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"1",1*/
- {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"2",2*/
- {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"3",3*/
- {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"4",4*/
- {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"5",5*/
- {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"6",6*/
- {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"7",7*/
- {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"8",8*/
- {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"9",9*/
- {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"a",
- 0*/
- {0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"b",
- 1*/
- {0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"c",
- 2*/
- {0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"d",
- 3*/
- {0x00,0xFC,0x00,0x00,0xFF,0x00,0x00,0xF0,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,
- 0x00,0x87,0x40,0x30,0x0F,0x00,0x00,0x1F,0x00,0x00,0xFF,0x08,0x10,0x0F,0x00,0x00},/*"帅",
- 4*/
- {0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00,
- 0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00}};/*"我"
- ,5*/
- unsigned char i;
- void delay(uint x)//延时
- {
- uint a,b;
- for(a=x;a>0;a--)
- for(b=10;b>0;b--);
- }
- void keydelay(uint i)
- {
- while(i--);
- }
- void delay2s(void) //误差 0us
- {
- unsigned char a,b,c;
- for(c=127;c>0;c--)
- for(b=235;b>0;b--)
- for(a=32;a>0;a--);
- _nop_(); //if Keil,require use intrins.h
- }
- void readbusy(void) /* 判断最高位是否为 1,为 0 才读写数据 */
- {
- P0=0x00;
- cons=P0;
- DI=0;
- RW=1;
- E=1;
- while(cons&0x80);
- E=0;
- }
- void Select(uchar i)
- {
- switch(i)
- {
- case 0:CS1=0;CS2=0;break;
- case 1:CS1=0;CS2=1;break;
- case 2:CS1=1;CS2=0;break;
- default:break;
- }
- }
- void xieminling(uchar value)
- {
- readbusy();/* 每次读写都要忙判断 */
- DI=0;
- RW=0;
- P0=value;
- E=1;
- _nop_();
- _nop_();
- E=0;
- }
- void Setonoff(uchar onoff)
- {
- onoff=0x3e|onoff;
- xieminling(onoff);
- }
- void xieshuju(uchar dat)
- {
- readbusy();
- DI=1;
- RW=0;
- P0=dat;
- E=1;
- _nop_();
- _nop_();
- E=0;
- }
- void Setpage(uchar page)/* 设置页 */
- {
- page=0xb8|page;
- xieminling(page);
- }
- void Setline(uchar line) /* 设置列 */
- {
- line=0x40|line;
- xieminling(line);
- }
- void qingping(uchar screen) /* 清屏*/
- {
- uchar i,j;
- Select(screen);
- for(i=0;i<8;i++)
- {
- Setline(0);
- Setpage(i);
- for(j=0;j<64;j++)
- {
- xieshuju(0x00);
- }
- }
- }
- void chushihua(void)
- {
- Select(0);
- Setonoff(0);
- Select(0);
- Setonoff(1);
- Select(0);
- qingping(0);
- }
- void xianshi(uchar ss,uchar lie,uchar page1,uchar *p)
- {
- uchar i;
- Select(ss);
- Setpage(page1);
- Setline(lie);
- for(i=0;i<16;i++)
- {
- xieshuju(p[i]);
- }
- Setpage(page1+1);
- Setline(lie);
- for(i=0;i<16;i++)
- {
- xieshuju(p[i+16]);
- }
- }
- void main()
- {
- chushihua();
- while(1)
- {
-
- xianshi(1,0,0,shuzi[15]); //第一个1开左边显示、2开右边显示
- xianshi(2,0,0,shuzi[14]); //第二个0/16/32第一个字、第二个字
- xianshi(1,0,2,shuzi[15]); //第三个0/2/4第一行、第二行
- xianshi(2,0,2,shuzi[14]);
- xianshi(1,16,4,shuzi[15]);
- xianshi(2,16,4,shuzi[14]);
- }
- }
复制代码 全部资料51hei下载地址:
proteus仿真12864 取模软件.zip
(1 MB, 下载次数: 222)
|