內(nèi)含仿真程序
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei圖片_20241106214102.png (233.92 KB, 下載次數(shù): 0)
下載附件
2024-11-6 21:42 上傳
單片機源程序如下:
- #include<reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define data1 P0//上8行數(shù)據(jù)口
- #define data2 P2//下8行數(shù)據(jù)口
- sbit x1=P1^7; //矩陣第1行所接端口
- sbit x2=P1^6; //矩陣第2行所接端口
- sbit x3=P1^5; //矩陣第3行所接端口
- sbit x4=P1^4; //矩陣第4行所接端口
- sbit y1=P1^3; //矩陣第1列所接端口
- sbit y2=P1^2; //矩陣第2列所接端口
- sbit y3=P1^1; //矩陣第3列所接端口
- sbit y4=P1^0; //矩陣第4列所接端口
- bit fangxiang;//方向標志位
- uchar dand1,dand2,dand3;//單獨顯示標志位
- uchar bilibili;//圖1放大減小標志位
- uchar xiaolian;//圖2放大減小標志位
- uchar tu3;//圖3放大減小標志位
- uchar quanliang,quanmie,bianyan;//全亮檢測,全滅檢測,邊沿檢測標志位
- uchar aa;//用于數(shù)據(jù)輸出數(shù)據(jù)數(shù)組時的讀取
- uchar sudu=5;//移動速度
- uint alt=0,net=0, zishu=3; //要寫幾個漢字就寫幾,數(shù)字和字母是1個字符,占用0.5個漢字位置,例如要顯示“你好1” 那么zishu變量要復制2.5
- //alt 計時變量,用于控制速度的計時變量
- //net 顯示哪個字的變量
- bit mode;
- uchar code tab[]={ //右移數(shù)組
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",1*/ //這兩行不用動,改字時保留
- 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x28,0x08,0x28,0x48,0x1B,0xA8,0x08,0x28,
- 0x08,0x28,0x18,0x28,0x2B,0xA8,0x28,0x48,0x08,0x08,0x0F,0xF8,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\bilibili.bmp",0*/
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x14,0x30,0x14,0x18,0x00,0x08,0x00,0x08,
- 0x00,0x08,0x00,0x08,0x14,0x18,0x14,0x30,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\笑臉.bmp",0*/
-
- 0x00,0x00,0x03,0xE0,0x0C,0x38,0x10,0x0C,0x23,0xE6,0x44,0x32,0x48,0x12,0x48,0x12,
- 0x48,0x22,0x48,0x62,0x4F,0xF2,0x48,0x16,0x60,0x34,0x38,0xE0,0x0F,0x80,0x00,0x00,/*"C:\Users\23725\Desktop\C51_點陣(顯示圖形,可移動)\PCtoLCD2002完美版--字摸提取軟件\@.bmp",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",14*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",15*/ //這兩行不用動,改字時保留
- };
- uchar code tab1[]={//左移函數(shù)
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",1*/ //這兩行不用動,改字時保留
-
- 0x00,0x00,0x03,0xE0,0x0C,0x38,0x10,0x0C,0x23,0xE6,0x44,0x32,0x48,0x12,0x48,0x12,
- 0x48,0x22,0x48,0x62,0x4F,0xF2,0x48,0x16,0x60,0x34,0x38,0xE0,0x0F,0x80,0x00,0x00,/*"C:\Users\23725\Desktop\C51_點陣(顯示圖形,可移動)\PCtoLCD2002完美版--字摸提取軟件\@.bmp",0*/
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x14,0x30,0x14,0x18,0x00,0x08,0x00,0x08,
- 0x00,0x08,0x00,0x08,0x14,0x18,0x14,0x30,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\笑臉.bmp",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x28,0x08,0x28,0x48,0x1B,0xA8,0x08,0x28,
- 0x08,0x28,0x18,0x28,0x2B,0xA8,0x28,0x48,0x08,0x08,0x0F,0xF8,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\bilibili.bmp",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",14*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",15*/ //這兩行不用動,改字時保留
- };
- uchar code tab2[]={ //bilibili 圖案數(shù)組
- 0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x28,0x08,0x28,0x48,0x1B,0xA8,0x08,0x28,
- 0x08,0x28,0x18,0x28,0x2B,0xA8,0x28,0x48,0x08,0x08,0x0F,0xF8,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\bilibili.bmp",0*/
- };
- uchar code tab3[]={ //笑臉 圖案數(shù)組
- 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x14,0x30,0x14,0x18,0x00,0x08,0x00,0x08,
- 0x00,0x08,0x00,0x08,0x14,0x18,0x14,0x30,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Users\23725\Desktop\笑臉.bmp",0*/
- };
- uchar code tab4[]={ //@ 圖案數(shù)組
- 0x00,0x00,0x03,0xE0,0x0C,0x38,0x10,0x0C,0x23,0xE6,0x44,0x32,0x48,0x12,0x48,0x12,
- 0x48,0x22,0x48,0x62,0x4F,0xF2,0x48,0x16,0x60,0x34,0x38,0xE0,0x0F,0x80,0x00,0x00,/*"C:\Users\23725\Desktop\C51_點陣(顯示圖形,可移動)\PCtoLCD2002完美版--字摸提取軟件\@.bmp",0*/
- };
- uchar code tab5[]={//bilibili放大圖案
- 0x00,0x00,0x3F,0xFE,0x20,0x02,0xA0,0x02,0xA0,0x62,0x67,0x12,0x20,0x0A,0x20,0x0A,
- 0x20,0x0A,0x20,0x0A,0x20,0x0A,0x67,0x12,0xA0,0x62,0xA0,0x02,0x20,0x02,0x3F,0xFE,
- };
- uchar code tab6[]={//笑臉放大圖案
- 0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x18,0x50,0x0C,0x50,0x04,0x00,0x04,0x00,0x04,
- 0x00,0x04,0x00,0x04,0x50,0x04,0x50,0x04,0x40,0x0C,0x00,0x18,0x00,0x10,0x00,0x00,
- };
- uchar code tab7[]={//@ 放大圖案數(shù)組
- 0x03,0xE0,0x0E,0x38,0x18,0x0C,0x20,0x06,0x43,0xE2,0x47,0x31,0x84,0x11,0x88,0x11,
- 0x88,0x21,0x88,0x61,0x8F,0xF3,0xCE,0x12,0x40,0x10,0x60,0x30,0x38,0xE0,0x0F,0x80,
- };
- uchar code tab8[]={//全亮檢測數(shù)組
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- };
- uchar code tab9[]={//全滅檢測數(shù)組
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- uchar code tab10[]={//邊沿檢測數(shù)組
- 0xFF,0xFF,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
- 0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0xFF,0xFF,
- };
- void delay(uint z) //延時子函數(shù)
- {
- uchar x;
- for(;z>0;z--)
- for(x=121;x>0;x--);
- }
- void PanDuan()//判斷顯示模式函數(shù)
- {
- if(dand1)
- {
- if(bilibili)
- {
- data1=tab5[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab5[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- data1=tab2[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab2[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- }
- else
- {
- if(dand2)
- {
- if(xiaolian)
- {
- data1=tab6[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab6[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- data1=tab3[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab3[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- }
- else
- {
- if(dand3)
- {
- if(tu3)
- {
- data1=tab7[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab7[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- data1=tab4[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab4[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- }
- else
- {
- if(quanliang)
- {
- data1=tab8[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab8[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- if(quanmie)
- {
- data1=tab9[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab9[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- if(bianyan)
- {
- data1=tab10[aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab10[aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- if(fangxiang==0)
- {
- data1=tab[net+aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab[net+aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- else
- {
- data1=tab1[net+aa]; //取出上8行數(shù)據(jù)輸出
- aa++;
- data2=tab1[net+aa]; //取出下8行數(shù)據(jù)輸出
- aa++;
- }
- }
- }
- }
- }
- }
-
- }
- }
- void xianshi()//顯示函數(shù)
- {
- uchar i;
- if(fangxiang==0)//向右移動
- {
- for(i=0;i<16;i++)
- {
- P3=i; //列掃描
- PanDuan();//判斷顯示模式
- delay(2); //延時
- data1=0; //清屏
- data2=0; //清屏
- P3=0x00; //消除余輝
- if(aa>30)
- aa=0; //字模地址
- }
- }
- else//向左移動
- {
- for(i=0;i<16;i++)
- {
- P3=i; //列掃描
- PanDuan();//判斷顯示模式
- delay(2); //延時
- data1=0; //清屏
- data2=0; //清屏
- P3=0x00; //消除余輝
- if(aa>30) aa=0; //字模地址
- }
- }
-
- }
- void scan_key(void)//矩陣鍵盤按鍵掃描函數(shù)
- {
- //檢測第一行
- x1=0; x2=1; x3=1; x4=1;
- if(y1==0)//開始/停止移動按鍵
- {
- delay(30); //延時消抖
- if(y1==0)
- {
- TR1=~TR1; //按下暫停 ,暫按繼續(xù)
- while(!y1) xianshi();
- }
- }
- else if(y2==0)//左右移動切換
- {
- delay(30); //延時消抖
- if(y2==0)
- {
- fangxiang=~fangxiang; //方向取反
- if(fangxiang==0) net=0;
- else net=(zishu+1)*32;
- while(!y2) xianshi();
- }
- }
- else if(y3==0)//增加延時,移動速度減
- {
- delay(30);
- if(y3==0)
- {
- sudu++;
- if(sudu>10)
- sudu=10;
- while(!y3) xianshi();
- }
- }
- else if(y4==0)//減少延時,移動速度加
- {
- delay(30);
- if(y4==0)
- {
- sudu--;
- if(sudu<1)
- sudu=1;
- while(!y4) xianshi();
- }
- }
- //檢測第二行按鍵
- x1=1; x2=0; x3=1; x4=1;
- if(y1==0) //單獨顯示圖1
- {
- delay(30);
- if(y1==0)
- {
- dand1=!dand1;
- dand2=0;
- dand3=0;
- quanliang=0;
- quanmie=0;
- bianyan=0;
- while(!y1) xianshi();
- }
- }
- else if(y2==0) //單獨顯示圖2
- {
- delay(30);
- if(y2==0)
- {
- dand1=0;
- dand2=!dand2;
- dand3=0;
- quanliang=0;
- quanmie=0;
- bianyan=0;
- while(!y2) xianshi();
- }
- }
- else if(y3==0) //單獨顯示圖3
- {
- delay(30);
- if(y3==0)
- {
- dand1=0;
- dand2=0;
- dand3=!dand3;
- quanliang=0;
- quanmie=0;
- bianyan=0;
- while(!y3) xianshi();
- }
- }
- else if(y4==0)//放大圖1
- {
- delay(30);
- if(y4==0)
- {
- bilibili=1;
- while(!y4) xianshi();
- }
- }
- //檢測第三行按鍵
- x1=1; x2=1; x3=0; x4=1;
- if(y1==0)//減小圖1
- {
- delay(30);
- if(y1==0)
- {
- bilibili=0;
- while(!y1) xianshi();
- }
- }
- else if(y2==0)//放大圖2
- {
- delay(30);
- if(y2==0)
- {
- xiaolian=1;
- while(!y2) xianshi();
- }
- }
- else if(y3==0)//減小圖2
- {
- delay(30);
- if(y3==0)
- {
- xiaolian=0;
- while(!y3) xianshi();
- }
- }
- else if(y4==0)//放大圖3
- {
- delay(30);
- if(y4==0)
- {
- tu3=1;
- while(!y4) xianshi();
- }
- }
- //檢測第四行按鍵
- x1=1; x2=1; x3=1; x4=0;
- if(y1==0)//減小圖3
- {
- delay(30);
- if(y1==0)
- {
- tu3=0;
- while(!y1) xianshi();
- }
- }
- else if(y2==0)
- {
- delay(30);
- if(y2==0)
- {
- quanliang=!quanliang;
- dand1=0;
- dand2=0;
- dand3=0;
- quanmie=0;
- bianyan=0;
- while(!y2) xianshi();
- }
- }
- else if(y3==0)
- {
- delay(30);
- if(y3==0)
- {
- quanmie=!quanmie;
- dand1=0;
- dand2=0;
- dand3=0;
- quanliang=0;
- bianyan=0;
- while(!y3) xianshi();
- }
- }
- else if(y4==0)
- {
- ……………………
- void main() //主函數(shù)
- {
- ET1=1; //使能定時器0
- EA=1; //開啟總中斷
- TR1=1; //開始計數(shù)
- TH1=0x3c;
- TL1=0xb0;
- while(1) //無限循環(huán)
- {
- xianshi(); //顯示
- scan_key();
- }
- }
-
- void timer1() interrupt 3//定時器1中斷服務函數(shù),通過改變計時的快慢改變移動的速度
- {
- TH1=0x3C;
- TL1=0xB0;
- alt++; //計時變量,用于控制速度的計時變量
- if(alt>=5*sudu) //到一定的時間加以實現(xiàn)左移
- {
- alt=0;
- if(fangxiang==0) //如果是正向 正向移動
- {
- net=net+2;//列左移
- if(net>((zishu+1)*32)) //字移動數(shù)量
- net=0;
- }
- else //否則反向移動
- {
- net=net-2;//列右移
- if(net<2)
- net=(zishu+1)*32; //字移動數(shù)量
- }
- }
- }
復制代碼
仿真程序:
C51_16x16點陣(顯示圖形,可移動,矩陣鍵盤).7z
(172.81 KB, 下載次數(shù): 5)
2024-11-6 21:53 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|