<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > AVR單片機課程設計程序

AVR單片機課程設計程序

作者: 時(shí)間:2012-10-17 來(lái)源:網(wǎng)絡(luò ) 收藏

//課程設計程序
//名稱(chēng):電壓表
//硬件:AVR-ATMEGA16 實(shí)驗板 8MHz 晶振
//編寫(xiě)人:李春起
//修改日志:

#includeiom16v.h>  #include macros.h>//-------------位拉高宏--------------------------------------------#define ADC0_H PORTA|=BIT(PA0) #define ADC1_H PORTA|=BIT(PA1)   #define LEDLK_H PORTA|=BIT(PA2)  //選通#define SEGLK_H PORTA|=BIT(PA3)  //段碼選通#define BITLK_H PORTA|=BIT(PA4)  //位選通//#define 18B20_H PORTA|=BIT(PA5) #define BEEP_H PORTA|=BIT(PA6)   //蜂鳴器#define CUSB_H PORTA|=BIT(PA7) //-------------位拉低宏--------------------------------------------#define ADC0_L PORTA=~BIT(PA0)  #define ADC1_L PORTA=~BIT(PA1)    #define LEDLK_L PORTA=~BIT(PA2)   #define SEGLK_L PORTA=~BIT(PA3)   #define BITLK_L PORTA=~BIT(PA4)   //#define 18B20_L PORTA=~BIT(PA5)  #define BEEP_L PORTA=~BIT(PA6)  #define CUSB_L PORTA=~BIT(PA7)  //----------單獨按鍵宏定義--------------------------------#define S1 (PIND0X01)==0 #define S2 (PIND0X02)==0#define S3 (PIND0X04)==0#define S4 (PIND0X08)==0#define NOP() asm("nop")#define uchar unsigned char #define uint unsigned int//============全局變量======================================uint adc0,flag,voldata;//AD轉換結果//===================數據表==============================================__flash uchar SEG[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0xff};//===============mS延時(shí)子程序============================================void delayms(uint m){uint i,j;for(i=0;im;i++){for(j=0;j1141;j++);}}//==================IO口初始化=======================================void IO_init(void){DDRA = 0Xfe;DDRB = 0Xff;DDRC = 0XFF;DDRD = 0XFF;PORTD= 0XFF;}//====================定時(shí)器T0初始化===================================void timer0_init(void){TCCR0 = 0x0c;  //256分頻 CTC模式TCNT0 = 0x00;  //計數器清0OCR0  = 100;   //187*256/8M=4.16mSTIMSK |=0x02;  //使能OCIE0TIFR  |=0x02;  //清OCIF0中斷標識位}//=================初始化======================================void init(void){IO_init();BEEP_H;timer0_init();}//===============AD轉換===========================void read_adc(void) {   ADMUX =0x00;//選擇PA0轉換通道   ADCSRA=0xE6;//開(kāi)始AD轉換 while ((ADCSRA  0x10)==0); //等待ad轉換結束 adc0 = ADCL;adc0 |= ADCH8; }//===================消殘影========================================void clear_LED(void){SEGLK_H;PORTB=0x00;  SEGLK_L;}//===================顯示==========================void disp(void){SEGLK_H;PORTB=SEG[adc0%10];SEGLK_L;BITLK_H;PORTB=0xdf;BITLK_L;delayms(3);clear_LED();SEGLK_H;PORTB=SEG[(adc0/10)%10];SEGLK_L;BITLK_H;PORTB=0xef;BITLK_L;delayms(3);clear_LED();SEGLK_H;PORTB=SEG[(adc0/100)%10];SEGLK_L;BITLK_H;PORTB=0xf7;BITLK_L;delayms(3);clear_LED();SEGLK_H;PORTB=SEG[adc0/1000];SEGLK_L;BITLK_H;PORTB=0xfb;BITLK_L;delayms(3);clear_LED();SEGLK_H;PORTB=SEG[0];SEGLK_L;BITLK_H;PORTB=0xfd;BITLK_L;delayms(3);clear_LED();SEGLK_H;PORTB=SEG[0];SEGLK_L;BITLK_H;PORTB=0xfe;BITLK_L;delayms(3);clear_LED();clear_LED();}//================================================//------------------------------------------------//--------------主函數----------------------------//------------------------------------------------void main(void){init();SFIOR=0X00;SREG|=0x80;adc0=1224;LEDLK_H;PORTB=0XFF;//滅掉LEDLK_L;while(1){read_adc();// disp();voldata=adc0;}}//---------------------------------------------//---------------------------------------------//=============================================//====================定時(shí)器T0中斷服務(wù)子程序========================#pragma interrupt_handler Timer0_Interrupt:20void Timer0_Interrupt(void){TCNT0 = 0X00;TIFR  |=0x02;  //清OCIF0中斷標識位clear_LED();switch(flag){case 0:{SEGLK_H;PORTB=SEG[voldata%10];SEGLK_L;BITLK_H;PORTB=0xdf;BITLK_L;flag=1;}break;case 1:{SEGLK_H;PORTB=SEG[(voldata/10)%10];SEGLK_L;BITLK_H;PORTB=0xef;BITLK_L;flag=2;}break;case 2:{SEGLK_H;PORTB=SEG[(voldata/100)%10];SEGLK_L;BITLK_H;PORTB=0xf7;BITLK_L;flag=3;}break;case 3:{SEGLK_H;PORTB=SEG[voldata/1000];SEGLK_L;BITLK_H;PORTB=0xfb;BITLK_L;flag=0;}break;default:break;}  


關(guān)鍵詞: AVR單片機 流水燈 數碼管

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>