` 本帖最后由 Fortware 于 2013-12-20 21:40 编辑
最近无聊,看到同学做课程设计,顺便玩了一下,主要实现点的流动,实现一种动态效果,同样使用74HC595来驱动点阵显示。程序如下:
- #include
- #include
- #define uchar unsigned char
- #define uint unsigned int
- ***it DS=P0^0; //数据输入
- ***it SH_CP=P0^1;
- ***it ST_CP=P0^2;
- uchar code row[]={
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x80,
- 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x20,
- 0x10,0x08,0x04,0x02,0x02,0x02,0x02,0x02,
- 0x02,0x02,0x04,0x08,0x10,0x20,0x40,0x40,
- 0x40,0x40,0x40,0x40,0x20,0x10,0x08,0x04,
- 0x04,0x04,0x04,0x04,0x08,0x10,0x20,0x20,
- 0x20,0x20,0x10,0x08,0x08,0x08,0x10,0x10};
- uchar code column[]={
- 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
- 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0xbf,
- 0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfe,0xfe,
- 0xfe,0xfe,0xfe,0xfe,0xfd,0xfb,0xf7,0xef,
- 0xdf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xdf,
- 0xef,0xf7,0xfb,0xfd,0xfd,0xfd,0xfd,0xfd,
- 0xfb,0xf7,0xef,0xdf,0xdf,0xdf,0xdf,0xef,
- 0xf7,0xfb,0xfb,0xfb,0xf7,0xef,0xef,0xf7,
- };
- void delayms(uint a)
- {
- uint x,y;
- for(x=a;x>0;x--)
- for(y=110;y>0;y--);
- }
- void delayus()
- {
- _nop_();_nop_();
- }
- void write_data(uchar dat_row,uchar dat_column)
- {
- uchar i;
- for(i=0;i<8;i++) //写行数据
- {
- SH_CP=0;
- DS=dat_row&0x80;
- SH_CP=1;
- dat_row<<=1;
- SH_CP=0;
- }
- for(i=0;i<8;i++) //写列数据
- {
- SH_CP=0;
- DS=dat_column&0x80;
- SH_CP=1;
- dat_column<<=1;
- SH_CP=0;
- }
- ST_CP=0; //上升沿并行输出
- delayus();
- ST_CP=1;
- }
- int main(void)
- {
- char i;
- while(1)
- {
-
- for(i=0;i<64;i++)
- {
- write_data(row[i],column[i]);
- delayms(15);
- }
- delayms(250);
- for(i=63;i>=0;i--)
- {
- write_data(row[i],column[i]);
- delayms(20);
- }
- delayms(250);
- }
- }
复制代码
效果图如下:
proteus 仿真图+源程序:
`
|