Saturday, July 5, 2014

BUJJI BUG PART 5

Everyone would like to operate the BUJJI BUG at their individual speed. To INCREASE/DECREASE speed of the KEY we are using EEPROM.

For this we need to WRITE and READ the value from EEPROM. Hence we are giving a small tutorial on how to do.

This can be used  in other programs also to store the value after the POWER CUT .

; BUJJI BUG
; Code to WRITE and READ from the EEPROM

        processor 16F628A                             ; Selected 16F628A
        #include <P16F628A.INC>                 ; Including the headerfile

; In this program we writing into EEPROM and reading the value back to PORTB
; We are suppose to use EEPROM for INCREMENT/DECREMENT the KEY speed.
; For checking the working of EEPROM. we are giving a small example program.
; To varify we connected an LED's from PORTB through the resistor.

        ORG         0X00                                  ; Starting address for microcontroller program
        NOP                                                    ; NO operation
        NOP                                                    ; NO operation
        NOP                                                    ; NO operation
        NOP                                                    ; This location is reserved for INTERRUPT and
;Initialising the INPUT and OUTPUT ports

        CLRF             PORTB                         ; Clearing the PORTB registers
        MOVLW        0X07                             ; Moving the "7(HEX)" into the W register
        MOVWF        CMCON                       ; Comparators are disabled
        BSF               STATUS,RP0                ; Selecting BANK 1
        BCF               STATUS,RP1               ; Selecting BANK 1
        CLRF             TRISB                          ; Making PORTB as OUTPUT
; Writing into EEPROM
        MOVLW        0X00                             ; Writing value 0 into W register
        MOVWF        EEADR                         ; Selecting the Address 0 in EEPROM to write
        MOVLW        0X10                             ; Moving value 10 (HEX) in W register
        MOVWF        EEDATA                       ; Selecting the value 10 (HEX) to write into EEPROM
        BSF               EECON1,WREN         ; Enabling the WRITE cycle
;......................................................................................................
        MOVLW       0X55                             ; Writing value 55 (HEX) into W register
        MOVWF       EECON2                       ; Passing the value into the EECON2 REGISTER
        MOVLW       0XAA                            ; Writing value AA (HEX) into W register
        MOVWF       EECON2                       ; Passing the value into the EECON2 REGISTER
;......................................................................................................
;Without the above four step the data cannot read into the EEPROM
        BSF               EECON1,WR                ; Enabling WR bit of EECON1 to write into the EEPROM
wait    BTFSC        EECON1,WR               ; Varifying whether the data is written into EEPROM or not
        GOTO           wait                                ; If yes skip this line otherwise goto wait
; Reading from EEPROM
        MOVLW      0X00                            ; Writing value 55 (HEX) into W register
        MOVWF      EEADR                        ; Selecting the address 0 in EEPROM to read
        BSF               EECON1,RD              ; Enabling the RD bit to Read the data from EEPROM
        MOVF          EEDATA,W                 ; Moving the data into the W register
wait1   BTFSC      EECON1,RD               ; Varifying whether the data is written into EEPROM or not
        GOTO          wait1                             ; If yes skip this line otherwise goto wait1
        BCF              STATUS,RP0              ; Coming back to BANK 0
        BCF              STATUS,RP1              ; Coming back to BANK 0
        MOVWF      PORTB                        ; Writing the EEPROM DATA into PORTB
        END                                                  ; END of the program


; NOTE 1:  11 instruction are used out of 35
; NOTE 2:  9 SPECIAL FUNCTION REGISTER used 38
; NOTE 3:  31 Bytes of memory is used
; NOTE 4:  The program is running with internal oscillator at default 4MHz clock speed.

   
 HEX Code:

:020000040000FA
:100000000000000000000000860107309F008316FA
:100010000313860100309B0010309A001C155530E8
:100020009D00AA309D009C149C18142800309B0051
:0E0030001C141A081C181A28831203138600C9
:00000001FF

No comments:

Post a Comment