; 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 ## ;######################### w_tmp EQU 0x20 ; Temp reg for W, in both banks (0x20 and 0xA0) stat_tmp EQU 0x21 ; Temp reg for Status ;######################### ;## 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 ; Save W and STATUS movwf w_tmp ; saving W register to actual page movf STATUS,W ; saving STATUS register to W movwf stat_tmp ; saving STATUS register from W to stat_tmp register ; Check IRQ from timer 0 btfss INTCON,T0IF ; ** Do we have TMR0 overflow? goto Irq_n1 ; -> skip to label Irq_nl bcf INTCON,T0IF ; -> Clear interrupt bit call Switch_diods Irq_n1 ; No we don't have TMR0 interrupt ; Restore W and STATUS movf stat_tmp,W movwf STATUS movf w_tmp,W 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 0xff movwf GPIO ; Turn off LED1 and 2 leds, turn on LED3 ;############### ; Set TIMER0 PAGE1 movlw b'111' ; Divider 1:256 movwf OPTION_REG; PAGE0 bcf INTCON,T0IF ; Clear T0_OVER flag bsf INTCON,T0IE ; Enable T0 IRQ clrf TMR0 ; Clear TMR bsf INTCON,GIE ; Enable all interrupt ;####################################### ; MAIN LOOP ;####################################### goto $ Switch_diods movlw LED1_P ; Flip led xorwf GPIO return end