单片机16*16点阵仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
点阵由于电流比较大不能直接接单片机所以用74hc595驱动串转并芯片,还可以实现用很少的io口来控制.
单片机源程序如下:
- #include "reg51.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define Lie P1
- sbit SHCP = P2^0;
- sbit DS = P2^1;
- sbit STCP = P2^2;
- uchar code led[ ] ={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x08,0x40,0x08,0x40,0x0A,0x48,0xEA,0x4B,0xAA,0x4A,0xAA,0x4A,0xAA,0x4A,0xFE,0x7F,
- 0xAA,0x4A,0xAA,0x4A,0xA9,0x4A,0xF9,0x4B,0x29,0x48,0x0C,0x60,0x08,0x40,0x00,0x00, // 重
- 0x00,0x40,0x00,0x20,0xFC,0x9F,0x44,0x80,0x44,0x40,0x44,0x20,0x44,0x18,0x45,0x06,
- 0xFE,0x01,0x44,0x06,0x44,0x18,0x44,0x20,0x66,0x40,0x44,0xC0,0x00,0x40,0x00,0x00, //庆
- 0x80,0x80,0x80,0x40,0xFC,0x3F,0x96,0x02,0xA5,0x44,0x84,0x80,0xFC,0x7F,0x08,0x80,
- 0x08,0x40,0xC9,0x3F,0x4A,0x00,0x4E,0x00,0xE8,0x3F,0x4C,0x40,0x08,0x70,0x00,0x00, //航
- 0x40,0x80,0x42,0x80,0x42,0x40,0x42,0x20,0x42,0x10,0x42,0x0C,0x42,0x03,0xFE,0x00,
- 0x42,0x03,0x42,0x0C,0x42,0x10,0x42,0x20,0x43,0x40,0x62,0xC0,0x40,0x40,0x00,0x00, //天
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- //uchar led[]={}
- void shift16bit(uchar dat1,uchar dat2) //595输出16位数据
- {
- uchar i;
- STCP=0;
- for(i=0;i<8;i++)
- {
- SHCP=0;
- if(dat1 &0x80) DS=1;
- else DS=0;
- dat1<<=1;
- SHCP=1;
- }
- for(i=0;i<8;i++)
- {
- SHCP=0;
- if(dat2 &0x80) DS=1;
- else DS=0;
- dat2<<=1;
- SHCP=1;
- }
- STCP=1;
- }
- void delay(uint x)
- {
- uint i;
- for(i=0;i<x;i++);
- }
- void main()
- {
- uchar i,x=0;
- uint n;
-
- while(1)
- {
- for(n=0;n<10;n++)
- for(i=0;i<16;i++)
- {
- Lie=i;
- shift16bit(led[2*i+1+2*x],led[2*i+2*x]);
- delay(100);
- }
- x++;
- if(x==64) x=0;
- /*
- for(n=0;n<100;n++)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
16by16点阵.rar
(226.09 KB, 下载次数: 136)
|