- /***********************************************************************************************************
- 实现汉字向上滚动显示
- P5用于译码器LM138实现静态扫描(低四位驱动),P4用于LM595串行转并行。
- LM595采用级联,可输入多个字节。DS为LM595的数据口,SH上升沿保存串口数据
- ,ST上升沿推DS数据到LM595输出端,ST下降沿将输出端锁存。
- 运行时显示小组标志和“黑客电子小组”向上滚动输出。
- 硬件资源:
- MSP430F155、LM595(两个)、LM138(两个)、8*8LED点阵(四个)
- ************************************************************************************************************/
- #include "msp430x15x.h"
- #define DATADIR P5DIR // 译码器控制设定输出
- #define CTLDIR P4DIR // 串行转并行芯片控制设定输出
- #define DATAOUT P5OUT
- #define CTLOUT P4OUT
- #define SH_L CTLOUT &= ~BIT0; // SH为低电位
- #define ST_L CTLOUT &= ~BIT1; // ST为低电位
- #define DS_L CTLOUT &= ~BIT2; // DS为低电位
- #define SH_H CTLOUT |= BIT0; // SH为高电位
- #define ST_H CTLOUT |= BIT1; // ST为高电位
- #define DS_H CTLOUT |= BIT2; // DS为高电位
- typedef unsigned int uint16;
- char table[64]; //用于存放其它数组
- char tab_0[]={0x00,0x00,0xE0,0x07,0x38,0x1E,0x20,0x04,0x38,0x1C,0x20,0x04,0x38,0x1C,0x20,0x04,
- 0x38,0x1C,0x20,0x04,0x38,0x1C,0x20,0x04,0x38,0x1C,0xE0,0x07,0x00,0x00,0x00,0x00};
- // 小组标志
- char tab_1[]={0x08,0x00,0xFC,0x3F,0x08,0x21,0x28,0x31,0x38,0x2D,0x48,0x25,0x08,0x21,0xF8,0x3F,
- 0x00,0x01,0xFC,0x7F,0x00,0x01,0xFE,0xFF,0x00,0x00,0x90,0x28,0x4C,0x24,0x44,0x44};
- // *黑*
- char tab_2[]={0x00,0x02,0x00,0x01,0xFE,0x7F,0x02,0x48,0xF4,0x8F,0x20,0x08,0x40,0x14,0x80,0x23,
- 0x60,0x0C,0x1E,0x30,0xE4,0xCF,0x20,0x08,0x20,0x08,0x20,0x08,0xE0,0x0F,0x20,0x08};
- // *客*
- char tab_3[]={0x00,0x02,0x00,0x02,0x10,0x02,0xF8,0x7F,0x10,0x42,0x10,0x42,0xF0,0x7F,0x10,0x42,
- 0x10,0x42,0xF0,0x7F,0x10,0x42,0x00,0x02,0x04,0x02,0x04,0x02,0xFC,0x01,0x00,0x00};
- // *电*
- char tab_4[]={0x00,0x00,0xF0,0x3F,0x10,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x04,0x01,0xFE,0xFF,
- 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02};
- // *子*
- char tab_5[]={0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x40,0x05,0x20,0x05,0x10,0x09,
- 0x08,0x09,0x04,0x11,0x04,0x21,0x00,0x41,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02};
- // *小*
- char tab_6[]={0x00,0x10,0x08,0x10,0xFC,0x21,0x08,0x21,0x08,0x45,0x08,0xF9,0xF8,0x11,0x08,0x21,
- 0x08,0x41,0x08,0xFD,0xF8,0x41,0x08,0x01,0x08,0x1D,0x08,0xE1,0xFE,0x47,0x00,0x00};
- // *组*
- void WriteByte(char send) // 发送一个字节
- {
- char temp_wb,i_wb;
- SH_L;
- for(i_wb=0;i_wb<8;i_wb++)
- {
- temp_wb = send & 0X80;
- if(temp_wb==0) DS_L;
- if(temp_wb!=0) DS_H;
- SH_H;
- send <<= 1;
- _NOP(); // 延时一个机器周期
- SH_L;
- }
- }
- void WriteLine(char *data_wl)
- {
- char i_wl;
- ST_L;
- for(i_wl=16;i_wl>0;i_wl--) // 由于两个595级联,故一次写入两个字节
- {
- WriteByte(*data_wl++);
- WriteByte(*data_wl++);
- ST_H; // ST上升沿推送数据
- DATAOUT = i_wl-1; // 扫描第几行
- ST_L; // ST下降沿锁存
- }
- }
- void arrcpy(char *arr1,char *arr2) // 将数组arr2复制到arr1
- {
- char i;
- for(i=0;i<32;i++)
- *arr1++ = *arr2++;
- }
- void arrcat(char *arr1,char *arr2) // 将数组arr2连接到arr1后面
- {
- char i;
- for(arr1+=32,i=0;i<32;i++)
- *arr1++ = *arr2++;
- }
- void dis_move(char *p_dis) // 移动扫描
- {
- char i1,i2;
- for(i1=0;i1<17;i1++)
- {
- p_dis = &table[i1*2];
- for(i2=0;i2<10;i2++)
- WriteLine(p_dis);
- }
- }
- void display() // 移动显示
- {
- arrcpy(table,tab_0); // 将tab_0复制到table
- arrcat(table,tab_1); // 将tab_1连接到table
- dis_move(table); // 将table移动显示
- arrcpy(table,tab_1);
- arrcat(table,tab_2);
- dis_move(table);
- arrcpy(table,tab_2);
- arrcat(table,tab_3);
- dis_move(table);
- arrcpy(table,tab_3);
- arrcat(table,tab_4);
- dis_move(table);
- arrcpy(table,tab_4);
- arrcat(table,tab_5);
- dis_move(table);
- arrcpy(table,tab_5);
- arrcat(table,tab_6);
- dis_move(table);
- arrcpy(table,tab_6);
- arrcat(table,tab_0);
- dis_move(table);
- }
- void main( void )
- {
- // Stop watchdog timer to prevent time out reset
- WDTCTL = WDTPW + WDTHOLD;
- DATADIR = 0X0F; // 设定数据为低四位输出
- CTLDIR = 0X07; // 设定控制为低三位输出
- while(1)
- {
- display();
- }
-
- }
复制代码
|