oriol escote wrote: > > Hi, > Colud anybody tell me where I can found an example program or tutorial about > PIC16F873 Analog/Digital converter. > > Thanks I have am A2D tutorial in PDF format that also uses an LCD if you are interested. It includes 6 ASM files which can be simulated in MPLAB, or programmed into a 16F873. Let me know if you want a copy. This simple program will read PORTA pin 0, but not much explanation... ; Title "Analog example" ; list P = 16F873 ; include "P16f873.inc" ; ; CRYSTAL SPEED = 4000000Hz ; ; ; ---------------- ; CODE BEGINS HERE ; ---------------- ; org 0x0000 Start movlw b'00000000' ; all port pins = low movwf PORTA movlw b'00000000' movwf PORTB movlw b'00000000' movwf PORTC bsf STATUS,RP0 movlw b'00000001' ; all port pins = output movwf TRISA ; except RA0 movlw b'00000000' movwf TRISB movlw b'00000000' movwf TRISC ; ; ------------------------- ; ENABLE RA0 ONLY AS ANALOG ; ------------------------- ; data is right justified in ADRESH and ADRESL ; movlw b'10001110' movwf ADCON1 bcf STATUS,RP0 ; ; -------------------------------------- ; ENABLE THE ANALOG TO DIGITAL CONVERTOR ; -------------------------------------- ; movlw b'11000001' ; A2D clock = RC, Ch 0, A2D = on movwf ADCON0 ; ; -------------------- ; START A2D CONVERSION ; -------------------- ; bsf ADCON0,GO_DONE ; ; ------------------------------- ; WAIT FOR CONVERSION TO COMPLETE ; ------------------------------- ; A2Dwait btfsc ADCON0,GO_DONE ; completed when GO_DONE = 0 goto A2Dwait ; ; ------------------------------ ; RESULT IS IN ADRESH AND ADRESL ; xxxxxx00 00000000 ; ------------------------------ ; ; do something with A2D result Here goto Here ; end -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.