⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iar9-7.c

📁 手把手教你学AVR单片机C程序设计实验程序
💻 C
字号:
#include <iom16.h>
#include<intrinsics.h>
#define uchar unsigned char
#define uint unsigned int
#define xtal 8
uchar __flash SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,	
                0x6d,0x7d,0x07,0x7f,0x6f};
uchar __flash ACT[8]={0xfe,0xfd,0xfb};	
uchar CNT;

void Delay_1ms(void)		
{ uint i;
 for(i=1;i<(uint)(xtal*143-2);i++)
    ;
}
//=============================================
void Delay_nms(uint n)		
{
 uint i=0;
   while(i<n)
   {Delay_1ms();
    i++;
   }
}

void port_init(void)		
{	
 DDRA=0xff;
 PORTA=0x00;
 DDRC=0xff;
 PORTC=0xff;
 DDRB=0xff;
 PORTB=0xff;
 DDRB=0x00; 
}			

void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0x00 /*INVALID SETTING*/; //set count
 OCR0  = 0x00 /*INVALID SETTING*/;  //set compare
 TCCR0 = 0x06; //start timer
}
	
/*********************************************/
void init_devices(void)	
{							
 port_init();		
 timer0_init();			
}							


/******************主函数******************/
void main(void)
{	
init_devices();
    while(1)			
    {	
    CNT=TCNT0;
    PORTA=SEG7[CNT%10];	
    PORTC=ACT[0];			
    Delay_nms(1);	
    PORTA=SEG7[(CNT/10)%10];	
    PORTC=ACT[1];			
    Delay_nms(1);
    PORTA=SEG7[CNT/100];	
    PORTC=ACT[2];			
    Delay_nms(1);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -