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.

PIC16F627A PROJECT

Status
Not open for further replies.

Tumelo

New Member
Friends I am struggling with this project : There is two switches, one at RB0, and the other at RB1; Two LED's that are sourcing current at RB4 and RB6; Two that are sinking current at RB5 and RB6... When the switch at RBO is pressed, the LED at RB4 must be on and the one atRB6 off. When the switch is released, LED at RB4 must be off and RB5 on... Same thing must also apply in switch 2, RB6 and RB7... Please help. I did it and it switches all led's when I press either switch 1 or 2.

HERE IS MY CODE>>>
Code:
LIST P = PIC16F627A

INCLUDE C:\Program Files (x86)\Microchip\MPASM Suite\p16f627a.inc

   org 00

   goto MAIN

FIRST_LED_ON:
   bsf 6,4        ;      turn port b pin 4 led on
   goto switch2 ;     goto next instructions

FIRST_LED_OFF:
   bcf 6,4       ;      turn port b pin 4 led off
   goto switch2       ;     goto next instructions

SECOND_LED_ON:
   bsf 6,6       ;      turn port b pin 6 led on
   goto switch2       ;      goto next instructions

SECOND_LED_OFF:
   bcf 6,6       ;      turn port b pin 6 led off
   goto switch1       ;      goto next instructions

THIRD_LED_ON:
   bsf 6,5       ;      turn port b pin 6 led on
   goto switch2       ;      goto next instructions

THIRD_LED_OFF:
   bcf 6,5       ;      turn port b pin 6 led off
   goto switch2       ;      goto next instructions

FOURTH_LED_ON:
   bsf 6,7       ;      turn port b pin 7 led on
   goto switch1      ;      goto next instructions

FOURTH_LED_OFF:
   bcf 6,7       ;      turn port b pin 7 led off
    goto switch1        ;       goto next instructions

MAIN:
   movlw 0x07       ;load 7
   movwf CMCON       ;disable comparator
   bsf 3,5        ;goto to bank 1 to configure the ports behaviour
   bcf 5,0       ;make pin 0 in port A output
   movlw b'00110000'       ;make pin 0-1 outputs and pin 4-5 inputs
   movwf 6       ;in portb
   bcf 3,5        ;go back to bank 0
   bsf 5,0       ;make pin 0 in port A on,to indicate that pic is on

switch1:        ;switch connected to portb pin 0
   btfss 6,0       ;check if switch is pressed
   goto FIRST_LED_OFF       ;turn off led when is not pressed
   goto FIRST_LED_ON         ;turn led on when is pressed
   goto THIRD_LED_OFF      ;turn led off at pin 5
   goto THIRD_LED_ON       ;turn led at pin 5 on when released

switch2: ;switch connected to portb pin 1
   btfss 6,1        ;check if switch is pressed
   goto SECOND_LED_OFF       ;turn off led at pin 6 when not pressed
   goto SECOND_LED_ON        ;turn led at pin 6 on when is pressed
   goto FOURTH_LED_OFF      ;turn led off at pin 7
   goto FOURTH_LED_ON       ;turn led at pin 7 on when released

end

Pleasse anyone.
 
Last edited by a moderator:
The order of your code is not easy to follow. Also, where you have;
bcf 6,7 ;turn port b pin 7 led off
You could use 'Bcf PortB ,7' instead.

Try arranging your code like this;
Code:
;Set up pic

Config
Processor type
Include file
turn off comparators,
Set PortB as switches and LEDs etc...

;---------------------------------------------------------------
Loop

Look at switch A and skip next line if it has not been pressed.
Goto 'Switch A pressed'

Look at switch B and skip next line if it has not been pressed.
Goto 'Switch B pressed'

Goto    Loop
;---------------------------------------------------------------
Switch A pressed

Switch some LEDs on,
Switch others off etc...

Goto    Loop
;--------------------
Switch B pressed

Switch some LEDs on,
Switch others off etc...

Goto    Loop
;---------------------------------------------------------------
End

See how you get on, it should be much easier to follow.
 
1)
Two LED's that are sourcing current at RB4 and RB6; Two that are sinking current at RB5 and RB6...
For the bolded pin, do you mean RB7? That is RB5 and RB7 are outputs and RB4 and RB6 are inputs? Also, I am assuming a pressed switch is LOW. Is that correct?

2)
movlw b'00110000' ;make pin 0-1 outputs and pin 4-5 inputs
Since RB0 and RB1 are being read as switches, shouldn't they be inputs?

3) From your description, this is my understanding:
upload_2015-10-7_17-0-7.png

UD = undefined
On/Off = state of the LED attached to that pin

Can you post a similar table with all states defined?

4) As a general suggestion, I find it easier to set the whole port, either by moving a literal to it or by XOR'ing with a literal. XOR'ing is really convenient, if you are just toggling some pins.

John

EDIT: I have attached my guess for this part of the schematic. Please modify as fit so we all are on the same page.
 

Attachments

  • ETO_16F627A.pdf
    10.3 KB · Views: 240
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top