Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Parking system

Status
Not open for further replies.

channnssss

New Member
Hi I'm working on a parking project. I'm building a PIC stimulus project that will be simulated only in the SFR window. It composes of 10 LEDs (5 green and 5 red ) and 5 switches. The LED will turn red if the switch is on (equal to logic 1). I'm a newbie in terms of coding and knowing its syntax. Can someone help? It would be much appreciated. Thanks in advance.


;********************************************************
;
; PIC Stimulus project
;
;
;********************************************************

PROCESSOR 16f84a
#include "p16f84a.inc"

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;**************** Label Definition ********************
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A


ra0 equ 00 ;RA1 bit
ra1 equ 01 ;RA1 bit
ra2 equ 02 ;RA2 bit
ra3 equ 03 ;RA3 bit
ra4 equ 04 ;RA4 bit




;************* Pattern Data Definition ****************
; '1':OFF '0':ON

;****** Pattern 0 ******
p00 equ b'11111111'
p01 equ b'11111110'
p02 equ b'11111101'
p03 equ b'11111100'
p04 equ b'11111011'
p05 equ b'11111010'



;**************** Program Start ***********************
org 0 ;Reset Vector
goto init
org 4 ;Interrupt Vector
goto init

;**************** Initial Process *********************

init bsf STATUS,5 ;Switch to Bank 1
movlw h'ff' ;Set input mode data
movwf TRISA ;Set PORTA to Input mode
clrf TRISB ;Set PORTB to Output mode
bcf STATUS,5 ;Change to Bank0
movlw h'ff' ;Set LED off data
movwf PORTB ;Output data

;**************** Key Scan Process ********************
keyscan btfss PORTA,ra0 ;RA0 ON(Low lebel) ?
call sw0 ;Yes. Call switch 0
btfss PORTA,ra1 ;RA1 ON(Low lebel) ?
call sw1 ;Yes. Call switch 1
btfss PORTA,ra2 ;RA2 ON ?
call sw2 ;Yes. Call switch 2
btfss PORTA,ra3 ;RA3 ON ?
call sw3 ;Yes. Call switch 3
btfss PORTA,ra4 ;RA4 ON ?
call sw4 ;Yes. Call switch 4
goto keyscan ;Retry

;*********** PORTA0 switch 0 Output Subroutine ***************
sw0 movlw p00 ;Set LED light
movwf PORTB ;Output data
return

;*********** PORTA1 switch 1 Output Subroutine ***************
sw1 movlw p01 ;Set LED light
movwf PORTB ;Output data
return

;*********** PORTA2 switch 2 Subroutine ***************
sw2 movlw p02 ;Set LED light
movwf PORTB ;Output data
return

;*********** PORTA3 switch 3 Subroutine ***************
sw3 movlw p03 ;Set LED light
movwf PORTB ;Output data
return

;*********** PORTA4 switch 4 Subroutine ***************
sw4 movlw p04 ;Set LED light
movwf PORTB ;Output data
return

;********************************************************
; END of PIC Stimulus project
;********************************************************

end
 
I know noting about the pIC, but

;**************** Program Start ***********************
org 0 ;Reset Vector
goto init
org 4 ;Interrupt Vector
goto init

Isn't going to work.

The label init doesn't exist.
ORG is usually an assembler directive telling the assembler where to place the code.

You can poll or use interrupts.
The interrupt routine has to be short and sweet. Get in and out quickly.
A program would essentially run an init routine and then wait for an interrupt.
An interrupt could be a pin change, but you have to set that up some how.
You might end up having a periodic interrupt where you would act on a flag set in the ISR (Interrupt Service Routine) so it's a lot more cpmplex.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top