I haven't written the code for brake cause I don't know how
list p=pic16f88
#include <p16f88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _CPD_OFF & _WRT_PROTECT_OFF & _CCP1_RB0 & _CP_OFF &_INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
errorlevel -302; gets rid of bank select error
;;;;;;;;;;;;;;Set up the constants;;;;;;;;;;;
TIME equ 9fh
PORTB equ 06h
TRISB equ 86h
PORTA equ 05h
TRISA equ 85h
STATUS equ 03h
RA0 equ H'0000'
RA1 equ H'0001'
RA2 equ b'0000010'
Temp equ 0ch
NOT_RPBU equ H'0007'
RB4 equ b'00001000'
cblock 0x20;declaring registers
d1
d2
d3
; register1;resister21
; register2;register22
; register3;register23
; register4;register24
endc
;;;;;;;;;;;;;;;Pattern Data Definition;;;;;;;
; '1':on '0':off
;;;;;;;;;;;;;;;LEFTturn pattern;;;;;;;;;;;;;;
p00 equ b'00100000'
p01 equ b'01000000'
p02 equ b'10000000'
;;;;;;;;;;;;;;;RIGHTturn pattern;;;;;;;;;;;;;
p03 equ b'00000100'
p04 equ b'00000010'
p05 equ b'00000001'
;;;;;;;;;;;;;;;HAZZARD pattern;;;;;;;;;;;;;;;
p06 equ b'00100100'
p07 equ b'01000010'
p08 equ b'10000001'
;;;;;;;;;;;;;;;BRAKE pattern;;;;;;;;;;;;;;;;;
p09 equ b'00001000'
p10 equ b'00000000'
;;;;;;;;;;;;;ALTERNATE PATTERNS;;;;;;;;;;;;;;
;;;;;;;;;;;;;LEFTturn1;;;;;;;;;;;;;;;;;;;;;;;;
p11 equ b'00100000'
p12 equ b'01100000'
p13 equ b'11100000'
;;;;;;;;;;;;RIGHTturn1;;;;;;;;;;;;;;;;;;;;;;;;
p14 equ b'00000100'
p15 equ b'00000110'
p16 equ b'000000111'
;;;;;;;;;;;;HAZZARD pattern1;;;;;;;;;;;;;;;;;
p17 equ b'00100100'
p18 equ b'01100110'
p19 equ b'11100111'
p20 equ b'00000000'; off pattern
;;;;;;;;;;;;;;;Program Start;;;;;;;;;;;;;;;;;
org 0 ;reset vector
goto init
org 4 ;interrupt vector
goto init
;;;;;;;;;;;;;;Set up the ports;;;;;;;;;;;;;;;
org 5
init
bsf STATUS,5
movlw b'01100000'
movwf OSCCON
WaitForStableOscillator
btfss OSCCON,IOFS
goto WaitForStableOscillator
movlw b'11111000' ; OPTION_REG setup
movwf OPTION_REG
clrf PIE1 ;
clrf PIE2 ; No peripherial interrupt
clrf ANSEL ; No analog to digital conversion
clrf TXSTA ;Disable AUSART
bcf STATUS,5
clrf INTCON ;No Interrupt control
clrf CCP1CON ;Capture/Compare/PWM Disabled
clrf T1CON ;No TIMER 1
;Watchdog Timer
bsf 83h,5
movlw b'00010111'
movwf WDTCON
bcf WDTCON,SWDTEN ;Disable watchdog timer
bsf STATUS,5
;PSA must be to WDA (bsf OPTION_REG,psa)
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bsf OPTION_REG,PS0
bcf STATUS,5
;General
clrf RCSTA ;Disable AUSART receive
clrf ADCON0 ;No analog to digital conversion
START
banksel ANSEL
movlw 0
movwf ANSEL
banksel CVRCON
bcf CVRCON,CVROE
bsf STATUS,RP0 ;SWITCH BANK0 TO BANK1
movlw b'11111111' ;SET INPUTS
movwf TRISA ;TO TRISA
movlw b'00000000' ;SET outputs
movwf TRISB
bcf STATUS,RP0
;;;;;;;;;;;;;Check if the bits are high;;;;;;;;;
keyscan
call BRAKE
clrf PORTB
btfss PORTA,RA0
goto keyscan1
btfss PORTA,RA1
call LEFTturn
goto keyscan2
keyscan1
clrf PORTB
btfss PORTA,RA1
goto keyscan
call RIGHTturn
goto keyscan
keyscan2
call HAZZARD
goto keyscan
;;;;;;;;;;;;LEFTTURNsubroutine;;;;;;;;;;;;;;;;;;
LEFTturn
call LOOP2
movlw p00 ;Set pattern data
movwf PORTB ;Output data
call LOOP2
movlw p01 ;Set pattern data
movwf PORTB
call LOOP2
movlw p02
movwf PORTB
call LOOP2
goto keyscan
;LEFTturn; alternate pattern1
call LOOP2
movlw p11 ;Set pattern data
movwf PORTB ;Output data
call LOOP2
movlw p12 ;Set pattern data
movwf PORTB
call LOOP2
movlw p13
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;RIGHTturn Subroutine;;;;;;;;;;;;;;;;;
RIGHTturn
call LOOP2
movlw p03
movwf PORTB
call LOOP2
movlw p04
movwf PORTB
call LOOP2
movlw p05
movwf PORTB
call LOOP2
return
;RIGHTturn; alternate pattern1
call LOOP2
movlw p14
movwf PORTB
call LOOP2
movlw p15
movwf PORTB
call LOOP2
movlw p16
movwf PORTB
call LOOP2
return
;RIGHTturn; alternate pattern2
call LOOP2
movlw p14
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p15
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p16
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;;HAZZARD Subroutine;;;;;;;;;;;;;;;;;
HAZZARD
call LOOP2
movlw p06
movwf PORTB
call LOOP2
movlw p07
movwf PORTB
call LOOP2
movlw p08
movwf PORTB
call LOOP2
return
;HAZZARD; alternatwe pattern1
call LOOP2
movlw p17
movwf PORTB
call LOOP2
movlw p18
movwf PORTB
call LOOP2
movlw p19
movwf PORTB
call LOOP2
return
;HAZZARD; alternatwe pattern2
call LOOP2
movlw p17
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p18
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p19
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;;;;;;;;;;;;;;;BRAKE subroutine;;;;;;;;;;;;;;;
BRAKE
btfss PORTA,RA2
return
call LOOP1
movlw p09
movwf PORTB
call LOOP1
movlw p10
movwf PORTB
call LOOP1
movlw p09
movwf PORTB
call LOOP1
movlw p10
movwf PORTB
call LOOP2
BRAKE1
movlw p09
movwf PORTB
return
;;;;;;;;;;;;;Delay Loop;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP0 ;1/8 sec delay
movlw 0xa7
movwf d1
movlw 0x62
movwf d2
Delay_0
decfsz d1,f
goto $+2
decfsz d2,f
goto Delay_0
goto $+1
return
LOOP1 ;1/4 sec delay
movlw 0x4f
movwf d1
movlw 0xc4
movwf d2
Delay_1
decfsz d1,f
goto $+2
decfsz d2,f
goto Delay_1
goto $+1
return
LOOP2; 1/2 sec delay
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_2
decfsz d1,f
goto $+2
decfsz d2,f
goto $+2
decfsz d3,f
goto Delay_2 ;6cycles
goto $+1
goto $+1
goto $+1
return
end
list p=pic16f88
#include <p16f88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _CPD_OFF & _WRT_PROTECT_OFF & _CCP1_RB0 & _CP_OFF &_INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
errorlevel -302; gets rid of bank select error
;;;;;;;;;;;;;;Set up the constants;;;;;;;;;;;
TIME equ 9fh
PORTB equ 06h
TRISB equ 86h
PORTA equ 05h
TRISA equ 85h
STATUS equ 03h
RA0 equ H'0000'
RA1 equ H'0001'
RA2 equ b'0000010'
Temp equ 0ch
NOT_RPBU equ H'0007'
RB4 equ b'00001000'
lightbuffer equ 30h
turnpattern equ 31h
brakepattern equ 32h
cblock 0x20;declaring registers
d1
d2
d3
; register1;resister21
; register2;register22
; register3;register23
; register4;register24
endc
;;;;;;;;;;;;;;;Pattern Data Definition;;;;;;;
; '1':on '0':off
;;;;;;;;;;;;;;;LEFTturn pattern;;;;;;;;;;;;;;
p00 equ b'00100000'
p01 equ b'01000000'
p02 equ b'10000000'
;;;;;;;;;;;;;;;RIGHTturn pattern;;;;;;;;;;;;;
p03 equ b'00000100'
p04 equ b'00000010'
p05 equ b'00000001'
;;;;;;;;;;;;;;;HAZZARD pattern;;;;;;;;;;;;;;;
p06 equ b'00100100'
p07 equ b'01000010'
p08 equ b'10000001'
;;;;;;;;;;;;;;;BRAKE pattern;;;;;;;;;;;;;;;;;
p09 equ b'00001000'
p10 equ b'00000000'
;;;;;;;;;;;;;ALTERNATE PATTERNS;;;;;;;;;;;;;;
;;;;;;;;;;;;;LEFTturn1;;;;;;;;;;;;;;;;;;;;;;;;
p11 equ b'00100000'
p12 equ b'01100000'
p13 equ b'11100000'
;;;;;;;;;;;;RIGHTturn1;;;;;;;;;;;;;;;;;;;;;;;;
p14 equ b'00000100'
p15 equ b'00000110'
p16 equ b'000000111'
;;;;;;;;;;;;HAZZARD pattern1;;;;;;;;;;;;;;;;;
p17 equ b'00100100'
p18 equ b'01100110'
p19 equ b'11100111'
p20 equ b'00000000'; off pattern
;;;;;;;;;;;;;;;Program Start;;;;;;;;;;;;;;;;;
org 0 ;reset vector
goto init
org 4 ;interrupt vector
goto init
;;;;;;;;;;;;;;Set up the ports;;;;;;;;;;;;;;;
org 5
init
bsf STATUS,5
movlw b'01100000'
movwf OSCCON
WaitForStableOscillator
btfss OSCCON,IOFS
goto WaitForStableOscillator
movlw b'11111000' ; OPTION_REG setup
movwf OPTION_REG
clrf PIE1 ;
clrf PIE2 ; No peripherial interrupt
clrf ANSEL ; No analog to digital conversion
clrf TXSTA ;Disable AUSART
bcf STATUS,5
clrf INTCON ;No Interrupt control
clrf CCP1CON ;Capture/Compare/PWM Disabled
clrf T1CON ;No TIMER 1
;Watchdog Timer
bsf 83h,5
movlw b'00010111'
movwf WDTCON
bcf WDTCON,SWDTEN ;Disable watchdog timer
bsf STATUS,5
;PSA must be to WDA (bsf OPTION_REG,psa)
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bsf OPTION_REG,PS0
bcf STATUS,5
;General
clrf RCSTA ;Disable AUSART receive
clrf ADCON0 ;No analog to digital conversion
START
banksel ANSEL
movlw 0
movwf ANSEL
banksel CVRCON
bcf CVRCON,CVROE
bsf STATUS,RP0 ;SWITCH BANK0 TO BANK1
movlw b'11111111' ;SET INPUTS
movwf TRISA ;TO TRISA
movlw b'00000000' ;SET outputs
movwf TRISB
bcf STATUS,RP0
movlw 03h
movwf turnpattern
movlw 02h
movwf brakepattern
clrf PORTB
;;;;;;;;;;;;;Check if the bits are high;;;;;;;;;
keyscan
clrf lightbuffer
btfss PORTA,RA2
call BRAKE
decfsz turnpattern
goto keyscan1
movlw 3h
movwf turnpattern
keyscan1
btfss PORTA,RA0
call RIGHTturn
btfss PORTA,RA1
call LEFTturn
movf lightbuffer,w
movwf PORTB
call LOOP2
goto keyscan
;;;;;;;;;;;;LEFTTURNsubroutine;;;;;;;;;;;;;;;;;;
LEFTturn
movf turnpattern,w
sublw 3h
btfss STATUS,Z
goto left1
movlw p00
xorwf lightbuffer
goto rightfin
left1
movf turnpattern,w
sublw 2h
btfss STATUS,Z
goto left2
movlw p01
xorwf lightbuffer
goto leftfin
left2
movlw p02
xorwf lightbuffer
leftfin
return
;LEFTturn; alternate pattern1
call LOOP2
movlw p11 ;Set pattern data
movwf PORTB ;Output data
call LOOP2
movlw p12 ;Set pattern data
movwf PORTB
call LOOP2
movlw p13
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;RIGHTturn Subroutine;;;;;;;;;;;;;;;;;
RIGHTturn
movf turnpattern,w
sublw 3h
btfss STATUS,Z
goto right1
movlw p03
xorwf lightbuffer
goto rightfin
right1
movf turnpattern,w
sublw 2h
btfss STATUS,Z
goto right2
movlw p04
xorwf lightbuffer
goto rightfin
right2
movlw p05
xorwf lightbuffer
rightfin
return
;RIGHTturn; alternate pattern1
call LOOP2
movlw p14
movwf PORTB
call LOOP2
movlw p15
movwf PORTB
call LOOP2
movlw p16
movwf PORTB
call LOOP2
return
;RIGHTturn; alternate pattern2
call LOOP2
movlw p14
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p15
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p16
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;;HAZZARD Subroutine;;;;;;;;;;;;;;;;;
;HAZZARD
decfsz turnpattern
goto haz1
movwf PORTB
call LOOP2
movlw p07
haz1
movwf PORTB
call LOOP2
movlw p08
movwf PORTB
call LOOP2
return
;HAZZARD; alternatwe pattern1
call LOOP2
movlw p17
movwf PORTB
call LOOP2
movlw p18
movwf PORTB
call LOOP2
movlw p19
movwf PORTB
call LOOP2
return
;HAZZARD; alternatwe pattern2
call LOOP2
movlw p17
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p18
movwf PORTB
call LOOP2
movlw p20
movwf PORTB
call LOOP0
movlw p19
movwf PORTB
call LOOP2
return
;;;;;;;;;;;;;;;;;;;;;;;;;;BRAKE subroutine;;;;;;;;;;;;;;;
BRAKE decfsz brakepattern
goto brake1
movlw p09
movwf lightbuffer
movlw 2h
movwf brakepattern
return
brake1
movlw p10
movwf lightbuffer
return
;;;;;;;;;;;;;Delay Loop;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP0 ;1/8 sec delay
movlw 0xa7
movwf d1
movlw 0x62
movwf d2
Delay_0
decfsz d1,f
goto $+2
decfsz d2,f
goto Delay_0
goto $+1
return
LOOP1 ;1/4 sec delay
movlw 0x4f
movwf d1
movlw 0xc4
movwf d2
Delay_1
decfsz d1,f
goto $+2
decfsz d2,f
goto Delay_1
goto $+1
return
LOOP2; 1/2 sec delay
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_2
decfsz d1,f
goto $+2
decfsz d2,f
goto $+2
decfsz d3,f
goto Delay_2 ;6cycles
goto $+1
goto $+1
goto $+1
return
end
SetUp bsf status,rp0
clrf trisA
decf trisA ;Make all RA input
clrf trisB ;Make all RB output
bcf status,rp0 ;select programming area - bank0
clrf portB ;Clear Port B of junk
movlw 07h ;turn comparators off and enable
movwf cmcon ; pins for I/O functions
goto Main
;****************************************************************
;* 1mS Delay *
;****************************************************************
_1mS nop
decfsz del,f
goto _1mS
retlw 00
;****************************************************************
;* Main *
;****************************************************************
Main movlw 0FFh
movwf counter ;number of 1mS loops
movf portA,w ;copy portA to w
movwf portB ;w to portB
call _1mS
call _1mS
decfsz counter,1
goto Main+2
movlw 0FFh
movwf counter ;number of 1mS loops
bcf portB,0
bcf portB,1
bcf portB,2
call _1mS
btfss portA,3 ;is brake OFF?
bcf portB,3
decfsz counter,1
goto $-4
goto Main
END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?