The code I have written so far only blinks constantly regardless of which switch is HIGH or LOW.. I can't seem to figure out how to make one switch faster than the others because it would either blink all switches at same rate or remain steady (doesn't blink). Could anyone help me out?????? Thank you!
Write a program that scans the switch settings and adjusts the blink rate of and LED according to those switch
settings.Your task is to write a program that detect the switch setting and slow down the flashing of the LED as each switch is set from LOW to HIGH. Your program should look like this. Note: ICSA.asm and switches.asm contain pieces of what you need.
1. Scan the switches
a. If Switch 1 is HIGH then change the blink timer and make it flash slower
b. If Switch 2 is HIGH then change the blink timer and make it flash slower
c. If Switch 3 is HIGH then change the blink timer and make it flash slower
d. If Switch 4 is HIGH then change the blink timer and make it flash slower
e. If Switch 5 is HIGH then change the blink timer and make it flash slower
f. If Switch 6 is HIGH then change the blink timer and make it flash slower
g. If Switch 7 is HIGH then change the blink timer and make it flash slower
h. If Switch 8 is HIGH then change the blink timer and make it flash slower
2. Blink the LED
3. Goto Scan the switches
;=============================================================================
; Assembled using MPASM 7.4
; Modified for 20Mhz at 9600 baud
;=============================================================================
; Include Files: p16f873A.inc V1.00
;=============================================================================
; The program
; 1. Turns RB7 on and off
; 2. Transmits characters
;
;=============================================================================
list p=16f873A, st=OFF, x=OFF, n=0
errorlevel -302
#include <p16f873A.inc>
__CONFIG _BODEN_OFF & _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC & _DEBUG_OFF & _CPD_OFF & _LVP_ON
;
;-----------------------------------------------------------------------------
; RS232 Constants
RTS_OUTPUT EQU 1 ;Port B Pin 1 output for flow control
CTS_INPUT EQU 2 ;Port B Pin 2 input for flow control
BAUD_CONSTANT EQU 0x81 ;Constant for baud generator for 9600 baud 20MHz
;-----------------------------------------------------------------------------
;Variables in bank0
CBLOCK 0x20
counter1: 1 ;delay counter
counter2: 1
counter3: 1
ENDC
;=============================================================================
;Reset vector code
ORG 0x0000
ResetVector
pagesel Init_RS232 ;select page for Init_RS232
goto Init_RS232 ;go to Init_RS232
;=============================================================================
;Start of code
ORG 0x0600 ;Use page 6
;Set up USART for asynchronous comms
;Routine is only called once and can be placed in-line saving a call and return
;This routine returns in bank0
Init_RS232
banksel PORTB ;change to PORTB bank
bsf PORTB, RTS_OUTPUT ;set RTS off before setting as output
banksel TRISB ;change to TRISB bank
bcf TRISB, RTS_OUTPUT ;enable RTS pin as output
movlw BAUD_CONSTANT ;set baud rate
movwf SPBRG
bsf TXSTA, BRGH ;baud rate high speed option
bsf TXSTA, TXEN ;enable transmission
banksel RCSTA ;change to RCSTA bank
bsf RCSTA, CREN ;enable reception
bsf RCSTA, SPEN ;enable serial port
Init_TRISA
Init_TRISB
banksel TRISB ;set i/o port data direction
bcf TRISB, 0x07 ;output=0
Send
banksel RCSTA
bcf RCSTA, CREN ;disable reception - clear reception
bsf RCSTA, CREN ;enable reception
pagesel Blink
call Blink
check
pagesel Send
goto Send
;----------------------------------------------------------------------------
Check_switches
;output 0 to decoder
banksel PORTB
bcf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bcf PORTB, 0x05 ;output=0=RB5=decoder input B
bcf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs - 1 micro second delay to compensate for 4051 chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 1 to decoder
banksel PORTB
bsf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bcf PORTB, 0x05 ;output=0=RB5=decoder input B
bcf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 2 to decoder
banksel PORTB
bcf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bsf PORTB, 0x05 ;output=0=RB5=decoder input B
bcf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 3 to decoder
banksel PORTB
bsf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bsf PORTB, 0x05 ;output=0=RB5=decoder input B
bcf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 4 to decoder
banksel PORTB
bcf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bcf PORTB, 0x05 ;output=0=RB5=decoder input B
bsf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 5 to decoder
banksel PORTB
bsf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bcf PORTB, 0x05 ;output=0=RB5=decoder input B
bsf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 6 to decoder
banksel PORTB
bcf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bsf PORTB, 0x05 ;output=0=RB5=decoder input B
bsf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
;output 7 to decoder
banksel PORTB
bsf PORTB, 0x04 ;output=0=RB4=decoder input A (low order)
bsf PORTB, 0x05 ;output=0=RB5=decoder input B
bsf PORTB, 0x06 ;output=0=RB6=decoder input C (high order)
nop ;NOPs to compensate for chips with slightly slower specifications
nop
nop
nop
nop
pagesel delay01
banksel PORTC
btfsc PORTC,0x05 ;RC5
call delay01
pagesel Check_switches
goto Check_switches
;----------------------------------------------------------------------------
Blink
pagesel Light_on
call Light_on
pagesel delay01
call delay01
pagesel Light_off
call Light_off
pagesel delay01
call delay01
return
Light_on
banksel PORTB
bsf PORTB, 0x07 ;RB7 = power on high
return
Light_off
banksel PORTB
bcf PORTB, 0x07 ;RB7 = power off low
return
;----------------------------------------------------------------------------
delay01 ;152ms counter1=00, counter2=00
movlw 0x00
banksel counter1
movwf counter1
movlw 0x00
banksel counter2
movwf counter2
movlw 0x05
banksel counter3
movwf counter3
delay02
banksel counter1 ;1
nop ;1
decfsz counter1 ;1
goto delay02
decfsz counter2
goto delay02
decfsz counter3
goto delay02
return
;-----------------------------------------------------------------------------
;Transmit byte in W register to USART
; transmit_data_in_w
; check for PORTB CTS_INPUT, clear to send with btfsc
; check for PIR1 TXIF, transmit buffer empty with btfss
; move w to TXREG to transmit byte
transmit_data_in_w
banksel PORTB ;change bank to PORTB
;btfsc PORTB, CTS_INPUT ;check CTS to see if data can be sent
;goto $-1
btfss PIR1, TXIF ;check that buffer is empty
goto $-1
movwf TXREG ;transmit byte
return
receive_data_in_w
banksel PORTB ;change bank to PORTB
bcf PORTB,RTS_OUTPUT ;set RTS on for data to be received
;btfss PIR1,RCIF ;check if data received
;goto $-1 ;wait until new data
movf RCREG,W ;get received data into W
return
nop
nop
nop
nop
nop
nop
nop
nop
end