📄 zhongduan.c
字号:
#include <avr/io.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char countnum[4]={0,0,0,0};
unsigned char a=0;
unsigned const char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
#pragma interrupt_handler int_0:2
unsigned char int_0()
{
a++;
}
/****************************************
* 函数名称: void delay_ms(uint i) *
* 函数功能:延时函数 *
* 晶振频率:7.3728MHZ *
* 入口参数:i mS *
****************************************/
void delay_us(unsigned int i)
{
while(i--)
{
asm("nop");
asm("nop");
}
}
/****************************************
* 函数名称: void delay_ms(uint i) *
* 函数功能:延时函数 *
* 晶振频率:7.3728MHZ *
* 入口参数:i mS *
****************************************/
void delay_ms(unsigned int i)
{
unsigned int a;
for(;i;i--)
{
for(a=570;a;a--)
{;}
}
}
//显示函数
void led(void)
{
unsigned char i;
static unsigned char lednum[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x3f};
//unsigned char countnum[4]={0,0,0,0};
DDRB=0xff;
PORTB=0xff;
DDRD=0x0f;
PORTD=0x0ff;
//显示计数值
for(i=0;i<4;i++)
{
PORTD&=~(1<<i);
if(2==i)
PORTB=lednum[countnum[i]]+0x80;
else
PORTB=lednum[countnum[i]];
delay_ms(1);
PORTD|=0xff;
}
//if(countnum[0]==9 && countnum[1]==9 && countnum[2]==9 && countnum[3]==9)
// break;
// }
//}
}
void main(void)
{
SREG=0X80;
GIMSK=0X40;
MCUCR=0X02;
DDRA=0;
DDRB=0XFF;
while(1)
{
PORTA=table[a];
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -