;************************************************************************** ; ; This Program developed by Peter Hayles for PIC 16C711 ; Flashes the LEDs on B1 and B2 ; at 2 and 200 timer intervals using the timer ; ; ;************************************************************************** #include "p16c711.inc" LIST P=16C711 ;-------------------------------------------------------------------------- ; Variables ;-------------------------------------------------------------------------- RAM EQU 0x10 Loop1 EQU RAM+0 Loop2 EQU RAM+1 Loop3 EQU RAM+2 Ones EQU RAM+3 Hunds EQU RAM+4 ;-------------------------------------------------------------------------- ; Program Code ;-------------------------------------------------------------------------- ORG 0 GOTO Start ORG 4 GOTO Interrupt ;-------------------------------------------------------------------------- ; Main Program ;-------------------------------------------------------------------------- ORG H'10' Start ; Set up I/O Ports MOVLW B'00011111' ; Port A 0-4=Input BSF STATUS,RP0 MOVWF TRISA MOVLW B'11111001' ; Port B 1,2=Output 0,3-7=Input BSF STATUS,RP0 MOVWF TRISB BSF STATUS,RP0 ; Enable weak pullups BCF OPTION_REG,NOT_RBPU ; Set PortB Pulled up BCF STATUS,RP0 MOVLW B'11111001' MOVWF PORTB ; Set up Timer CLRWDT ;Clear WDT and prescaler BSF STATUS,RP0 ;Assign prescaler and set it up BCF OPTION_REG,T0CS ;Internal Clock BCF OPTION_REG,PSA ;Prescaler ->Timer0 MOVLW B'000000111' ;1:128 Prescaler IORWF OPTION_REG,1 BCF STATUS,RP0 ; Set initial values CLRF Ones CLRF Hunds ; Setup for quick Interrupt entry the first time, and enable interrupts MOVLW H'FF' ;Dummy Value !! MOVWF TMR0 MOVLW B'10100000' ;Enable Timer0 Interrupt INTCON,GIE MOVWF INTCON Main NOP GOTO Main ; This routine gets entered every 1 second Interrupt CLRF INTCON ;Disable Interrupts during ISR INCF Ones,1 BTFSC Ones,0 GOTO ON1 CALL LED1OFF GOTO Next1 ON1 CALL LED1ON Next1 MOVLW D'100' SUBWF Ones,0 BTFSS STATUS,Z ;If Zero, then =100 GOTO Next2 INCF Hunds,1 CLRF Ones BTFSC Hunds,0 GOTO ON2 CALL LED2OFF GOTO Next2 ON2 CALL LED2ON Next2 MOVLW H'00' ;Enable Interrupt after a fixed number of cycles MOVWF TMR0 MOVLW B'10100000' ;Enable Timer0 Interupt INTCON,GIE MOVWF INTCON RETFIE ; LED Routines LED1ON BCF PORTB,1 RETLW 0 LED1OFF BSF PORTB,1 RETLW 0 LED2ON BCF PORTB,2 RETLW 0 LED2OFF BSF PORTB,2 RETLW 0 END