日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]/*****************************************************File name : AD_onchip.c Chip type : ATmega16L Program type : Application Clock frequency : 4.000000 MHz Memory model : Small External SRAM si

/*****************************************************

File name : AD_onchip.c
Chip type : ATmega16L
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
Function : 內(nèi)部AD轉(zhuǎn)換,數(shù)碼管顯示
*****************************************************/

#include
#include

#define hc164_data PORTD.0 // 164數(shù)據(jù)線
#define hc164_clk PORTD.1 // 164時(shí)鐘線

void hc164_send_byte (unsigned char byte); // 164輸出子程序
void leddisplay(void); // 數(shù)碼管顯示子程序

unsigned char ledxs[8]={16,16,16,16,0,0,0,0}; // 數(shù)碼管顯示緩沖區(qū)
// AD轉(zhuǎn)換值 千位 百位 十位 個(gè)位
flash unsigned char tab[]={0xb7,0x12,0x67,0x76,0xd2,0xf4,0xf5,0x16,0xf7,0xf6,0xd7,0xf1,0xa5,0x73,0xe5,0xc5,0,0xff};
//共陰極代碼 0-F, 全滅,全亮
bit time_2ms_ok; // 2ms時(shí)間到標(biāo)志

interrupt [TIM0_COMP] void timer0_comp_isr(void); // Timer 0 比較匹配中斷服務(wù)
interrupt [ADC_INT] void adc_isr(void); // ADC 轉(zhuǎn)換完成中斷服務(wù)

void main(void)
{
DDRA=0x0f;
PORTA=0x0f;
DDRD=0xff; // LED顯示控制I/O端口初始化
// T/C0 初始化
TCCR0=0x0B; // 內(nèi)部時(shí)鐘,64分頻(4M/64=62.5KHz),CTC模式
TCNT0=0x00;
OCR0=0x7C; // OCR0 = 0x7C(124),(124+1)/62.5=2ms
TIMSK=0x02; // 允許T/C0比較中斷

// ADC 初始化
ADMUX=0x47; // 參考電源AVcc、ADC7單端輸入
SFIOR&=0x1F;
SFIOR|=0x60; // 選擇T/C0比較匹配中斷為ADC觸發(fā)源
ADCSRA=0xAD; // ADC允許、自動(dòng)觸發(fā)轉(zhuǎn)換、ADC轉(zhuǎn)換中斷允許、ADCclk=125Kz
#asm("sei") // 開放全局中斷

while (1)
{
if (time_2ms_ok)
{
leddisplay(); // LED串行顯示
time_2ms_ok = 0;
delay_ms(1000);
}
}
}
// Timer 0 比較匹配中斷服務(wù)
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
time_2ms_ok = 1;
}

// ADC 轉(zhuǎn)換完成中斷服務(wù)
interrupt [ADC_INT] void adc_isr(void)
{
unsigned int ad_value;
unsigned char adl,adh;
adl = ADCL;
adh = ADCH;
ad_value = ((unsigned int)adh<<8)|adl; // 讀取AD轉(zhuǎn)換結(jié)果
ledxs[4] = ad_value/1000; // 求得AD轉(zhuǎn)換值千位
ledxs[5] = (ad_value%1000)/100; // 求得AD轉(zhuǎn)換值百位
ledxs[6] = (ad_value%100)/10; // 求得AD轉(zhuǎn)換值十位
ledxs[7] = (ad_value%100)%10; // 求得AD轉(zhuǎn)換值個(gè)位
}
void leddisplay() // 數(shù)碼管顯示子程序
{
unsigned char i;
for(i=0;i<8;i++)
{
hc164_send_byte (tab[ledxs[i]]);
delay_us(2);
}
}
void hc164_send_byte (unsigned char byte) // 164輸出子程序
{
unsigned char i;
for(i=0;i<8;i++)
{
hc164_data = byte & ( 1 << i );
hc164_clk = 1;
hc164_clk = 0;
}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉