您的位置 首页 新品

max7219操控8段数码管 spi接口

#includeiom16v.h>#defineuintunsignedint#defineucharunsignedchar#defineCS_HPORTB

#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;ifor(j=0;j<1141;j++);
}
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);

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/xinpin/272939.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部