RAYMOND WILLCOX wrote: > > Hi all > I would like to read a pot on portA 0 (a/d config) and write the values > to the EEPROM for storage and later output the data to portB. Is this > possible with a 16f873? Any code will be helpfull. Thanks in advance, Mark > ________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com I haven't tried it but it "should" work. (famous last words) ; Title " Basic EEPROM access and A2D code" ; list P = 16F873 ; include "P16f873.inc" ; ; CLOCK SPEED = 4MHz ; ; ; ------------- ; REGISTER LIST ; ------------- ; CBLOCK 0x20 temp ENDC ; ; --------- ; CONSTANTS ; --------- ; AnalogIn equ 0h ; Analog input (PORTA 0) WRN equ 2h ; WREN label defined different in some *.inc files ; ; ------------- ; PROGRAM START ; ------------- ; org 0h Start clrf PORTA clrf PORTB clrf PORTC bsf STATUS,RP0 movlw b'00000001' ; RA0 = input for A2D movwf TRISA clrf TRISB clrf TRISC bcf STATUS,RP0 movlw b'01000001' ; A2D = 0n, < Ch0 >, FOsc/8 movwf ADCON0 ; left justify clrf temp ; startup stabilize delay init decfsz temp goto init bsf STATUS,RP1 ; bank 2 clrf EEADR ; set eeprom address = 00h bcf STATUS,RP1 ; bank 0 ; ; -------------------------------- ; get an A2D value from preset CH0 ; -------------------------------- ; EELoop call GetA2D call Ewrite bsf STATUS,RP1 ; bank 2 incf EEADR btfsc EEADR,7 ; test if last EEPROM location (16F873) goto LastEEP bcf STATUS,RP1 ; bank 0 goto EELoop LastEEP clrf EEADR ; set eeprom address = 00h bcf STATUS,RP1 ; bank 0 ; ; ------------------------------------ ; READ DATA FROM EEPROM, SEND TO PORTB ; ------------------------------------ ; PTLoop call Eread movwf PORTB bsf STATUS,RP1 ; bank 2 incf EEADR btfsc EEADR,7 ; test if last EEPROM location (16F873) goto LastPT bcf STATUS,RP1 ; bank 0 goto PTLoop LastPT bcf STATUS,RP1 ; bank 0 here goto here ; ; -------------------------------------- ; A2D COVERSION - CHANNEL IS ALREADY SET ; -------------------------------------- ; data (upper 8 of 10 bits) returned in W ; GetA2D bsf ADCON0,GO_DONE ; (2) start conversion WaitA2D nop btfsc ADCON0,GO_DONE ; (2) goto WaitA2D movf ADRESH,W ; steer position data return ; ; ----------- ; EEPROM READ ; ----------- ; EEADR preset on entry, data returned in W ; Eread bsf STATUS,RP1 ; bank 2 bsf STATUS,RP0 ; bank 3 bcf EECON1,EEPGD ; make sure data EEPROM bsf EECON1,RD bcf STATUS,RP0 ; bank 2 movf EEDATA,W clrf STATUS ; bank 0 return ; ; ------------ ; EEPROM WRITE ; ------------ ; EEADR preset on entry, W = data to write ; Ewrite bsf STATUS,RP1 ; bank 2 movwf EEDATA bsf STATUS,RP0 ; bank 3 bcf EECON1,EEPGD ; make sure data EEPROM bsf EECON1,WRN movlw 55h movwf EECON2 movlw 0xaa movwf EECON2 bsf EECON1,WR WtEep nop btfsc EECON1,WR goto WtEep bcf EECON1,WRN clrf STATUS ; bank 0 return ; ; end -- Best regards Tony http://www.picnpoke.com mailto:sales@picnpoke.com