; I have released this source code as open source. Copy, modify, borrow, steal, I dont care ; If you DO happen to use it somewhere, credit would be nice but dont feel any obligation. ; There are absolutely no warranties either implied or expressed. ; This code is for the pic12c508a list p=12c508, r=dec ;------CPU EQUATES--------------------------------------------------------- ; all the equates below are boiler plate code. ;----- Register Files ----------------------------------------------------- INDF EQU H'0000' TMR0 EQU H'0001' PCL EQU H'0002' STATUS EQU H'0003' FSR EQU H'0004' OSCCAL EQU H'0005' GPIO EQU H'0006' ;----- STATUS Bits -------------------------------------------------------- GPWUF EQU H'0007' PA0 EQU H'0005' NOT_TO EQU H'0004' NOT_PD EQU H'0003' Z EQU H'0002' DC EQU H'0001' C EQU H'0000' ;----- OPTION Bits -------------------------------------------------------- NOT_GPWU EQU H'0007' NOT_GPPU EQU H'0006' T0CS EQU H'0005' T0SE EQU H'0004' PSA EQU H'0003' PS2 EQU H'0002' PS1 EQU H'0001' PS0 EQU H'0000' ;----- OSCCAL Bits -------------------------------------------------------- OSCFST EQU H'0003' OSCSLW EQU H'0002' ;========================================================================== ; ; RAM Definition ; ;========================================================================== __MAXRAM H'1F' ;========================================================================== ; ; Configuration Bits ; ;========================================================================== _MCLRE_ON EQU H'0FFF' _MCLRE_OFF EQU H'0FEF' _CP_ON EQU H'0FF7' _CP_OFF EQU H'0FFF' _WDT_ON EQU H'0FFF' _WDT_OFF EQU H'0FFB' _LP_OSC EQU H'0FFC' _XT_OSC EQU H'0FFD' _IntRC_OSC EQU H'0FFE' _ExtRC_OSC EQU H'0FFF' __CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC ;-------- PROGRAM START --------------------------------------------------------- ; set up the pins for i/o in the order that we need them to be. This may be ; changed later depending on board layout. ONTIME equ 0x07 ONTIMETEMP equ 0x08 OFFTIME equ 0x09 OFFTIMETEMP equ 0x0A org 0x00 ;Effective Reset Vector goto start start ; Initialize and setup the microcontroller. clrf GPIO ;Clear I/O Port movlw b'00001100' ;set the value in the working register to what the ouputs will be tris GPIO ;Set PortB as output (yes, I DO know its deprecated) ;this is the startup routines movlw b'11111111' movwf GPIO ;set all the bits high so that we can see its doing something. movlw b'00000000' ;and reset the timer. movwf TMR0 ; Set up the internal timer ; None of this code will ever need to be changed. movlw b'00010111' ;set up the option register, prescaler = 256 and set up the weak pull ups. option ;set the option register ;------------------------------------------------------------------------------ ;set up the initial timer values movlw b'00000001' movwf ONTIME movlw b'11111111' movwf OFFTIME movf ONTIME, 0 movwf ONTIMETEMP movf OFFTIME, 0 movwf OFFTIMETEMP loop movlw b'11111111' movwf GPIO movf ONTIME, 0 movwf ONTIMETEMP ;do the on time loop ON decfsz ONTIMETEMP goto ON movlw b'00000000' movwf GPIO movf OFFTIME, 0 movwf OFFTIMETEMP ;do the off time loop OFF decfsz OFFTIMETEMP goto OFF ;check to see if our timer has reached the predetermined time btfss TMR0, 6 goto loop movlw b'00000000' movwf TMR0 btfsc GPIO, 3 ;test pin 3 to see if they wanna shut the unit down. goto UP btfsc GPIO, 2 goto DOWN goto loop UP decf OFFTIME incf ONTIME GOTO loop DOWN decf ONTIME incfsz OFFTIME GOTO loop end