|
發表於 2012-6-23 23:33:11
|
顯示全部樓層
code 變更編碼為 big5
一開始是自己用手打的,可能有改到用詞用語,就抱歉啦~- #include<reg52.h> //包含head file,一般狀況是不需要變動的,head file包含特殊功能暫存器的定義
- #include <intrins.h>
- #include <delay.h>
- unsigned char segout[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //8列
- /*unsigned char code tab[96]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //空格
- 0x00,0x7E,0xFF,0xC3,0xC3,0xFF,0x7E,0x00, //字符0
- 0x00,0x00,0x43,0xFF,0xFF,0x03,0x00,0x00, //字符1
- 0x00,0x63,0xC7,0xCF,0xDB,0xF3,0x63,0x00, //字符2
- 0x00,0x42,0xDB,0xDB,0xDB,0xFF,0x66,0x00, //字符3
- 0x00,0x3E,0x46,0xFF,0xFF,0x06,0x06,0x00, //字符4
- 0x00,0xF6,0xF7,0xD3,0xD3,0xDF,0xDE,0x00, //字符5
- 0x00,0x7E,0xFF,0xDB,0xDB,0xDF,0x4E,0x00, //字符6
- 0x00,0xC0,0xC0,0xC7,0xFF,0xF8,0xC0,0x00, //字符7
- 0x00,0xFF,0xFF,0xDB,0xDB,0xFF,0xFF,0x00, //字符8
- 0x00,0x72,0xFB,0xDB,0xDB,0xFF,0x7E,0x00, //字符9
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //空格
- };*/
- unsigned char tab[85]={
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //空格},
- 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0xa0, 0x40, 0x00, 0x00,//J
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,//.
- 0x00, 0xf8, 0x48, 0x50, 0x70, 0x50, 0x40, 0x40, 0xe0, 0x00, 0x00,//F
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,//.
- 0x00, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x48, 0xf8, 0x00, 0x00,//L
- 0x00, 0xf8, 0x48, 0x50, 0x70, 0x50, 0x40, 0x48, 0xf8, 0x00, 0x00,//E
- 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00//U
- };
- /*------------------------------------------------
- 硬件端口定義
- ------------------------------------------------*/
- sbit LATCH = P1^0; //
- sbit SRCLK= P1^1;
- sbit SER = P1^2;
- sbit LATCH_B = P2^2;
- sbit SRCLK_B= P2^1;
- sbit SER_B= P2^0;
- /*------------------------------------------------
- 發送字節程序
- 帶有方向參數,可以選擇從高位節寫入或低位節寫入
- ------------------------------------------------*/
- void SendByte(unsigned char dat,bit direction)
- {
- unsigned char i,temp;
- if(direction==0)
- temp=0x80;
- else
- temp=0x01;
- for(i=0;i<8;i++)
- {
- SRCLK=0;
- SER=dat&temp;
- if(direction==0)
- dat<<=1;
- else
- dat>>=1;
- SRCLK=1;
- }
-
- }
- /*------------------------------------------------
- 發送雙字節程序
- ------------------------------------------------*/
- void Send2Byte(unsigned char dat1,unsigned char dat2,bit direction)
- {
- SendByte(dat1,direction);
- SendByte(dat2,direction);
- }
- /*------------------------------------------------
- 595鎖存程序
- ------------------------------------------------*/
- void Out595(void)
- {
- LATCH=0;
- _nop_();
- LATCH=1;
- }
- /*------------------------------------------------
- 發送位碼字節程序
- 使用另外一個單獨595
- ------------------------------------------------*/
- void SendSeg(unsigned char dat)
- {
- unsigned char i;
-
- for(i=0;i<8;i++) //發送字節
- {
- SRCLK_B=0;
- SER_B=dat&0x80;
- dat<<=1;
- SRCLK_B=1;
- }
- LATCH_B=0; //鎖存
- _nop_();
- LATCH_B=1;
-
- }
- /*------------------------------------------------
- 主程序
- ------------------------------------------------*/
- void main()
- {
- unsigned char i,k,l;
- while(1)
- {
- for(k=0;k<=77;k++) //shift 88 byte
- for(l=10;l>0;l--) //cycle times for same display word
- for(i=7;i>0;i--) //fill up 8x8 LED
- {
- SendSeg(segout[i]);
- Send2Byte((~(*(tab+i+k))),0xff,0);
- Out595();
- DelayMs(1);
- Send2Byte(0xff,0xff,0);//delay(10); //防止重影
- Out595();
- }
- for(k=0;k<=77;k++) //所有的字符個數
- for(l=8;l>0;l--) //延時長度,改變此值可以改變流動速度
- for(i=7;i>0;i--) //8列顯示
- {
- SendSeg(segout[7-i]);
- Send2Byte(0xff,~(*(tab+i+k)),0); //寫入字節方向改變
- Out595();
- DelayMs(1);
- Send2Byte(0xff,0xff,0);//delay(10); //防止重影
- Out595();
- }
- }
- }
複製代碼 |
|