我在別人做好的16×64點陣顯示屏上擴展了16×128點陣顯示屏。但是在程序運行后,兩塊16×64點陣顯示屏分別顯示,要修改哪條程序讓他可以在16×128點陣上從右往左顯示
單片機源程序如下:
- #include <reg51.H>
- #include <intrins.h>
- #define I2Cdelay() {_nop_();_nop_();_nop_();_nop_();}
- #define uchar unsigned char
- #define uint unsigned int
- uchar flag=1,yid,h; //YID為移動計數器,H為行段計數器
- //flag=1 左移顯示 flag=0靜態顯示
- uint zimuo; //字模計數器
- uchar BUFF[10]; //緩存
- void in_data(void); //調整數據
- void rxd_data(void); //發送數據
- void Scan(void); //掃描
- void I2CStart(void);
- void I2CWrite(uchar dat);
- sbit R=P2^0; //數據輸入端口
- sbit CLK=P2^1; //時鐘信號
- sbit STB=P2^2; //鎖存端
- sbit key=P3^2; //定義按鍵
- sbit I2C_SCL = P3^7;
- sbit I2C_SDA = P3^6;
- uchar code table[]={
- /*前4位無顯示*/
- 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,
- 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,
- 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,
- 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,
- /*-- 文字: 愛 --*/
- /*-- 宋體9; 此字體下對應的點陣為:寬x高=16x16 --*/
- 0x00,0x00,0x00,0x1E,0xFC,0x09,0x48,0x08,
- 0x90,0x04,0xFE,0x3F,0x42,0x20,0xFC,0x1F,
- 0x20,0x00,0xF0,0x0F,0x50,0x04,0x88,0x02,
- 0x04,0x01,0xC2,0x06,0x38,0x38,0x00,0x00,
- /*-- 文字: 我 --*/
- /*-- 宋體9; 此字體下對應的點陣為:寬x高=16x16 --*/
- 0x00,0x00,0x60,0x02,0x1C,0x0A,0x10,0x12,
- 0x10,0x02,0xFE,0x3F,0x10,0x02,0x10,0x12,
- 0x70,0x12,0x18,0x0A,0x16,0x0A,0x10,0x24,
- 0x10,0x2A,0x10,0x31,0x9C,0x20,0x00,0x00,
- /*-- 文字: 中 --*/
- /*-- 宋體9; 此字體下對應的點陣為:寬x高=16x16 --*/
- 0x00,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,
- 0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x10,
- 0x84,0x10,0xFC,0x1F,0x84,0x10,0x80,0x00,
- 0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,
- /*-- 文字: 華 --*/
- /*-- 宋體9; 此字體下對應的點陣為:寬x高=16x16 --*/
- 0x00,0x00,0x10,0x01,0x10,0x11,0x08,0x09,
- 0x0C,0x07,0x8A,0x01,0x68,0x21,0x08,0x21,
- 0x08,0x3E,0x88,0x00,0x80,0x00,0xFE,0x3F,
- 0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,
- /*后4位無顯示*/
- 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,
- 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,
- 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,
- 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,};
- void delay(int z) //延時
- {
- int x,y;
- for(x=0;x<z;x++)
- for(y=0;y<50;y++);
- }
-
- void main(void)
- {
- uchar i,speed=2;
- yid=0;
- zimuo=0;
- I2CStart();
- I2CWrite(0xA0); //10100001讀10100000寫
- EA=1;EX0=1;IT0=1; //全局中斷開,中斷0初始化
-
- while(1)
- {
- if(flag==1)
- {
- while(zimuo<8*32)
- { if(flag==1)
- {
- while(yid<16) //數據移位。
- { if(flag==1)
- {
- for(i=0;i<speed;i++) //移動速度
- {
- if(flag==1)
- {Scan();}
- else break;
- }
- yid++; //移動一步
- }
- else break;
- }
- yid=0;
- zimuo=zimuo+32; //后移一個字,
- }
- else break;
- }
- zimuo=0; //到最后從頭開始,有字數決定
- }
- else
- {
- zimuo=128; //靜態掃描從第一個中文字開始
- Scan();
- }
- }
- }
- /*----------中斷0的服務子程序-----------*/
- void int_0s() interrupt 0 using 0
- {
- if(key==0)
- {
- delay(2); //去抖
- if(key==0)
- flag=~flag;
- while(key==0); //等待按鍵釋放
- }
-
- }
- /*-------------掃描函數-----------------*/
- void Scan()
- {
- for(h=0;h<16;h++) //16行掃描
- {
- in_data(); //調整數據
- rxd_data(); //串口發送數據
- P1=h; //送行選
- STB=1;
- STB=0;
- delay(2);
- }
- }
- void in_data(void)
- {
- uchar s;
- for(s=0;s<5;s++)
- {
- BUFF[2*s]=table[zimuo+32*s+2*h]; /*把第一個字模的第一個字節放入BUFF0
- 中,第二個字模的第一個字節放入BUFF2中*/
- BUFF[2*s+1]=table[zimuo+1+32*s+2*h]; /* 把第一個字模的第二個字節放入BUFF1
- 中,第二個字模的第二個字節放入BUFF3中*/
- }
- }
-
- /**********74HC595輸出函數*************/
- void rxd_data(void) //串行發送數據
- {
- char s;
- uchar inc,tempyid,temp;
- uchar k;
- R=1;
- if(yid<8)
- inc=0;
- else
- inc=1;
- for(s=0+inc;s<=7+inc;s++) //發送2字節數據
- {
- if(yid<8)
- tempyid=yid;
- else
- tempyid=yid-8; //字模左邊字節右移tempyid位,右邊字節左移8-tempyid位,2者相或
- temp=(BUFF[s]>>tempyid)|(BUFF[s+1]<<(8-tempyid));
- for(k=0;k<8;k++)
- {
- I2C_SCL =1; //拉高SCL
- CLK=0;
- //R=(bit)(temp&0x80);
- temp=temp>>1;
- R=CY;
- CLK=1;
- I2C_SDA =R;
- I2C_SCL =0; //再拉低SCL,完成一個位周期
- }
- }
- }
- /*----------AT24C512-------------*/
- /* 產生總線起始信號 */
- void I2CStart()
- {
- I2C_SDA=1; //首先確保SDA、SCL都是高電平
- I2C_SCL=1;
- I2Cdelay();
- I2C_SDA=0; //先拉低SDA
- I2Cdelay();
- I2C_SCL=0; //再拉低SCL
- }
- /* I2C總線寫操作,dat-待寫入字節,返回值-從機應答位的值 */
- void I2CWrite(uchar dat)
- {
-
- uchar mask; //用于探測字節內某一位值的掩碼變量
- for (mask=0x80;mask!=0;mask>>=1) //從高位到低位依次進行
- {
- if ((mask&dat)==0) //該位的值輸出到SDA上
- I2C_SDA=0;
- else
- I2C_SDA=1;
- I2Cdelay();
- I2C_SCL=1; //拉高SCL
- I2Cdelay();
- I2C_SCL=0; //再拉低SCL,完成一個位周期
- }
- I2C_SDA=1; //8位數據發送完后,主機釋放SDA
-
- }
復制代碼
|