; Include file, change directory if needed #include "p12f675.inc" ;######################### ;## uC Chip settings ## ;######################### ; Set User ID Memory __idlocs 0x55aa ; Set configuration bits using definitions from the include file, p16f84.inc __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF ;######################### ;## PIN DEFINITIONS ## ;######################### ; GP5 I/O () ; GP4 I/O () ; GP3 nMCLR () ; GP2 I/O () ; GP1 OUT LED1 () ; GP0 OUT LED0 () LED1_P EQU b'111111' ; OUTPUTs LED1 EQU GP0 LED0 EQU GP1 ; INPUTs ;######################### ;## CONSTANTS ## ;######################### ;######################### ;## GLOBAL REGISTERS ## ;######################### tmp EQU 0x20 ; Temporary register count_l EQU 0x21 ; count_h EQU 0x22 ; ;######################### ;## MACROS ## ;######################### #define PAGE0 bcf STATUS,RP0 ; [M] Switch to page 0 in RAM #define PAGE1 bsf STATUS,RP0 ; [M] Switch to page 1 in RAM ;################################################################################### ;################################################################################### ;#### S T A R T #### ;################################################################################### ;################################################################################### ;Initialization of basic registers Reset_vector org 0x0000 goto Init Irq_vector org 0x0004 PAGE0 movlw 0b01 ; show that interrupt is OK bcf PIR1, EEIF PAGE1 movlw 0x11 ; Read address 0x10 from EEPROM movwf EEADR bsf EECON1,RD movf EEDATA,W ; and store it to tmp PAGE0 movwf GPIO retfie Init ; ############## ; Adjust osc calibration constant, read it from EEPROM PAGE1 ; Set page 0 call 0x3ff movwf OSCCAL ; Read osc calibration value and set it PAGE0 movlw 0x07 movwf CMCON ; Disable comparator PAGE1 movlw 0x00 movwf ANSEL ; Disable ADC movlw 0x00 movwf ADCON0 ; Disable ADC PAGE0 clrwdt ; Reset watchdog ;############### ; Set Inputs/Outputs PAGE1 movlw ~(LED1_P) ; LED1 will be output movwf TRISIO ; Set direction PAGE0 ; Set GPIO movlw 0x00 movwf GPIO ; Turn off LED1 and 2 leds, turn on LED3 ; configure interrupts PAGE1 bsf PIE1, EEIE PAGE0 bsf INTCON, PEIE bcf INTCON, GIE ;wait a bit ; call wait ;############### ; Read LED state from EEPROM and invert it: PAGE1 movlw 0x11 ; Read address 0x10 from EEPROM movwf EEADR bsf EECON1,RD movf EEDATA,W ; and store it to tmp addlw 0x01 PAGE0 movwf tmp ;incf tmp ; increment value by one ; Set GPIO state - all on ;PAGE0 ;movlw 0xff ;movwf GPIO ; Write back new value: movfw tmp PAGE1 movwf EEDATA ; Set EEPROM address and data to write movlw 0x11 movfw EEADR bsf EECON1,WREN ; Enable write movlw 0x55 ; Unlock write movwf EECON2 movlw 0xAA movwf EECON2 bsf EECON1,WR ; Write bsf INTCON, GIE ;Loop: ; Wait until the value is written successfully ;btfsc EECON1,WR ;goto Loop ;####################################### ; MAIN LOOP ;####################################### goto $ wait: clrw movwf count_l movlw 0x40 movwf count_h ; Set counter to 0x40 M_L1: incfsz count_l ; inner loop goto M_L1 incfsz count_h ; outer loop goto M_L1 return end