max7219控制8段数码管 spi接口
#include
#define uint unsigned int
#define uchar unsigned char
#define CS_H PORTB|=(1<4)
#define CS_L PORTB&=~(1<4)
void SPI_MasterInit(void)
{
/* 设置MOSI 和SCK 为输出,其他为输入 */
DDRB = (1<4)|(1<5)|(1<7);
/* 使能SPI 主机模式,设置时钟速率为fck/16 */
SPCR = (1
void SPI_MasterTransmit(uchar cData)
{
/* 启动数据传输 */
SPDR = cData;
/* 等待传输结束 */
while(!(SPSR & (1
void M7219_send(uchar b1,uchar b2)
{
CS_L;
SPI_MasterTransmit(b1);
SPI_MasterTransmit(b2);
CS_H;
}
void delay(uint ms)
{
uint i,j;
for(i=0;i
}
void main()
{
uchar i,j;
SPI_MasterInit();
//M7219_send(0x0f,0xff);
M7219_send(0x09,0xff);//手册说0x07 Code B decode for digits 7–0
//感觉有问题,直接写0xff了
M7219_send(0x0a,0x05);//Intensity Register
M7219_send(0x0b,0x07);//Display digits 0 1 2 3 4 5 6 7
M7219_send(0x0c,0x01);//开显示
while(1)
for(i=0;i<8;i++)
M7219_send(i+1,i);
}
max72198段数码管spi接 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)