📄 main.c
字号:
#include<iom16.h>
unsigned char num[30]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA7,0xA1,0x86,
0x8E,0x89,0x8B,0xC7,0xAB,0xC8,0xA3,0x8C,
0x98,0xAF,0x87,0xC1,0x91,0xBF};//字形码
/*******************************************************************************
函数名称:delay
函数功能:延时
*******************************************************************************/
void delay(int n)
{
for(int i=0;i<n;i++)
{;}
}
/*******************************************************************************
函数名称:io_init
函数功能:io初始化
*******************************************************************************/
void io_init(void)
{
DDRB|=DDB0+DDB5+DDB7+DDB1+DDB2+DDB3+DDB4; //相应管脚设置为输出
PORTB|=PORTB0+PORTB5+PORTB7+PORTB1+PORTB2+PORTB3+PORTB4;
}
/*******************************************************************************
函数名称:spi_init
函数功能:spi初始化
*******************************************************************************/
void spi_init(void)
{
SPCR|=SPE+DORD+MSTR+CPOL+CPHA;// 或者SPCR|=SPE+DORD+MSTR;
}
/*******************************************************************************
函数名称:display
函数功能:
*******************************************************************************/
void display(unsigned char number)
{
unsigned char c;
SPDR=num[number];
while(!(SPSR&SPIF));
c=SPSR;
c=SPDR;
c=c; //防止编译器出现警告
}
/*******************************************************************************
主函数
*******************************************************************************/
void main( void )
{
io_init();
spi_init();
while(1)
{
display(1);
PORTB&=~(PORTB1+PORTB2+PORTB3+PORTB4);//清显示
PORTB|=PORTB1;
delay(4500);
display(2);
PORTB&=~(PORTB1+PORTB2+PORTB3+PORTB4);//清显示
PORTB|=PORTB2;
delay(4500);
display(3);
PORTB&=~(PORTB1+PORTB2+PORTB3+PORTB4);//清显示
PORTB|=PORTB3;
delay(4500);
display(4);
PORTB&=~(PORTB1+PORTB2+PORTB3+PORTB4);//清显示
PORTB|=PORTB4;
delay(4500);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -