專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開發(fā)工具、應(yīng)用測(cè)試 完善的開發(fā)代碼案例庫(kù)分享
從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無(wú)限潛能!
提供新的芯片及解決方案,提升客戶產(chǎn)品競(jìng)爭(zhēng)力
提供最新的單片機(jī)資訊,行業(yè)消息以及公司新聞動(dòng)態(tài)
十年專注單片機(jī)方案開發(fā)的方案公司英銳恩,分享單片機(jī)AD轉(zhuǎn)換。英銳恩現(xiàn)提供服務(wù)產(chǎn)品涉及主控芯片:8位單片機(jī)、16位單片機(jī)、32位單片機(jī)及各類運(yùn)算放大器等。
w EQU 00h f EQU 01h STATUS EQU 03h PORTB EQU 06h INTCON EQU 0Bh PIR1 EQU 0Ch PIR2 EQU 0Dh TMR1L EQU 0Eh TMR1H EQU 0Fh T1CON EQU 10h T2CON EQU 11h ADRESH EQU 1Eh ADCON0 EQU 1Fh TRISB EQU 86h PIE1 EQU 8Ch ADCON1 EQU 9FH TRISA EQU 85H
LAST EQU 20h W_TEMP EQU 21h STATUS_TEMP EQU 22h Scaler EQU 23h LAST1 EQU 24h TEMP EQU 25h
org 000h nop goto main org 004h goto intservice
intservice movwf W_TEMP ;存儲(chǔ)w寄存器內(nèi)容 swapf STATUS,w movwf STATUS_TEMP btfsc PIR1,0 ;判斷TIMER1是否溢出中斷 call Timer1 ;調(diào)用Timer1中斷服務(wù)程序 swapf STATUS_TEMP,w movwf STATUS swapf W_TEMP,f swapf W_TEMP,w ;恢復(fù)w和status的內(nèi)容 retfie
Timer1 bcf STATUS,5 bcf PIR1,0 ;將TIMER1的中斷使能標(biāo)志清0 decf Scaler,f clrf TMR1L ;把TMR1清0,防止進(jìn)位產(chǎn)生 movlw 88h;;;;;;;;;; movwf TMR1H movlw 2fh movwf TMR1L return
main call Initial mainloop call Delay call ADConvert subwf LAST,w btfsc STATUS,2 goto mainloop movwf LAST1 movf TEMP,w movwf LAST btfsc STATUS,0 goto Display1 goto Display2 ;goto mainloop
Initial movlw 00h movwf LAST bcf STATUS,5 clrf PORTB movlw 04h movwf Scaler bsf STATUS,5 clrf TRISB ;設(shè)定B口為輸出口 bcf STATUS,5 clrf T1CON ;設(shè)定TIMER1的時(shí)鐘為FOSC/4,不使用分頻器 clrf TMR1H clrf TMR1L clrf INTCON bsf INTCON,6 ;將外圍功能的中斷使能 bsf STATUS,5 clrf PIE1 bsf PIE1,0 ;將TIMER1的溢出中斷使能 bcf STATUS,5 clrf PIR1 clrf TMR1L movlw 88h;;;;;;;;;; movwf TMR1H movlw 2fh movwf TMR1L ;bsf T1CON,0 ;TIMER1開始計(jì)數(shù) bsf STATUS,5 movlw B'00001110' ;選擇A/D轉(zhuǎn)換輸入端RA0,參考電壓為VDD及VSS movwf ADCON1 bsf TRISA,0 ;設(shè)定A口<0>為輸入端 bcf STATUS,5 movlw B'10000001' ;工作時(shí)鐘為FOSC/32,并啟動(dòng)A/D轉(zhuǎn)換模塊 movwf ADCON0 bsf INTCON,7 ;將中斷總開關(guān)打開,使中斷可以產(chǎn)生 return
ADConvert bcf STATUS,5 bsf ADCON0,2 ;執(zhí)行A/D轉(zhuǎn)換 wait btfsc ADCON0,2 goto wait movf ADRESH,w ;movlw B'00010000' andlw B'11111000' movwf TEMP bcf STATUS,0 rrf TEMP,f rrf TEMP,f rrf TEMP,f movf TEMP,w return
Display1 bcf STATUS,5 loop1 movlw B'11000000' movwf PORTB call Delay movlw B'01100000' movwf PORTB call Delay movlw B'00110000' movwf PORTB call Delay movlw B'10010000' movwf PORTB call Delay ;movlw B'11000000' ;movwf PORTB ;call Delay ;movlw B'01100000' ;movwf PORTB ;call Delay ;movlw B'00110000' ;movwf PORTB ;call Delay ;movlw B'10010000' ;movwf PORTB ;call
Delay decfsz LAST1,f goto loop1 movlw B'00000000' movwf PORTB bcf STATUS,0 goto mainloop Display2 bcf STATUS,5
loop2 movlw B'10010000' movwf PORTB call Delay movlw B'00110000' movwf PORTB call Delay movlw B'01100000' movwf PORTB call Delay movlw B'11000000' movwf PORTB call Delay ;movlw B'10010000' ;movwf PORTB ;call Delay ;movlw B'00110000' ;movwf PORTB ;call Delay ;movlw B'01100000' ;movwf PORTB ;call Delay ;movlw B'11000000' ;movwf PORTB ;call Delay incfsz LAST1,f goto loop2 movlw B'00000000' movwf PORTB bcf STATUS,0 goto mainloop
Delay bsf T1CON,0 ;TIMER1開始計(jì)數(shù) Delay1 btfss Scaler,7 ;檢查Scaler的第7位是否為0 goto Delay1 bcf T1CON,0 ;TIMER1停止計(jì)數(shù) clrf TMR1L ;把TMR1清0,防止進(jìn)位產(chǎn)生 movlw 88h;;;;;;;;;; movwf TMR1H movlw 2fh movwf TMR1L movlw 05h addwf Scaler,f return
end