PDA

View Full Version : Pic16f628 - Pic16f628a



nat22
- 8th July 2008, 21:19
Hello everyone, I am on the start of learning about PICs, I have found Nigel Goodwin web site and have found project for turning one LED on and in that time turn all other LED off.Program was made for PIC 16F628 and I tried to modifed it for PIC16F628A and it does not work. Here is the code, can someone tell me what is wrong.All LEDs are ON all the time,


;Tutorial 2.1 - Nigel Goodwin 2002
LIST p=16F628A ;tell assembler what chip we are using
include "P16F628A.inc" ;include the defaults for the chip

__CONFIG _INTOSC_OSC_CLKOUT

LEDPORT Equ PORTA ;set constant LEDPORT = 'PORTA'
SWPORT Equ PORTA ;set constant SWPORT = 'PORTA'
LEDTRIS Equ TRISA ;set constant for TRIS register
SW1 Equ 7 ;set constants for the switches
SW2 Equ 6
SW3 Equ 5
SW4 Equ 4
LED1 Equ 3 ;and for the LED's
LED2 Equ 2
LED3 Equ 1
LED4 Equ 0

;end of defines
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

bsf STATUS, RP0 ;select bank 1
movlw b'11110000' ;set PortA 4 inputs, 4 outputs
movwf LEDPORT
bcf STATUS, RP0 ;select bank 0

clrf LEDPORT ;set all outputs low

Loop btfss SWPORT, SW1
call Switch1
btfss SWPORT, SW2
call Switch2
btfss SWPORT, SW3
call Switch3
btfss SWPORT, SW4
call Switch4
goto Loop

Switch1 clrf LEDPORT ;turn all LED's off
bsf SWPORT, LED1 ;turn LED1 on
retlw 0x00

Switch2 clrf LEDPORT ;turn all LED's off
bsf SWPORT, LED2 ;turn LED2 on
retlw 0x00

Switch3 clrf LEDPORT ;turn all LED's off
bsf SWPORT, LED3 ;turn LED3 on
retlw 0x00

Switch4 clrf LEDPORT ;turn all LED's off
bsf SWPORT, LED4 ;turn LED4 on
retlw 0x00

end

thanks

nat22
- 9th July 2008, 06:44
Hello lester,

why is my thread moved? I am new at forum, I am beginner,

thanks

Melanie
- 9th July 2008, 07:09
Most probably because as a beginner, you posted in the wrong category (this is an MeLabs PICBASIC forum and not one for general ASSEMBLER). don't worry, you've not been deleted - just moved and everyone can still read your posts.

nat22
- 9th July 2008, 07:17
Hello Melanie,

thank you for your explanation,

best regards

Gurkan-demirbas
- 9th July 2008, 12:29
How have you connected the switch to the Port pin?
When you press the button; which logic level occurs on the pin? 5 Volt? 0 Volt?

Well if the port pin gets 5 volt when you press, ==> your btfss is wrong; How?
btfss SWPORT, SW1 ==> test SW1 and skip the next, if it is Logic1 (5 Vdc);
call Switch1 ==> if the pin is Logic0 (0 Vdc) then this command will be executed because of the previous.
Then, it will turn on the lights.

Change your hardware, or the simpler way is to change your code to....
btfsc SWPORT, SW1
call Switch1

The situation is the same for the other SWs and also other LEDs

GurkaN

nat22
- 21st July 2008, 10:42
Hello GurkaN,

sorry for delayed answer, a lot of work to be done.



How have you connected the switch to the Port pin?
When you press the button; which logic level occurs on the pin? 5 Volt? 0 Volt?
Well if the port pin gets 5 volt when you press, ==> your btfss is wrong; How?
btfss SWPORT, SW1 ==> test SW1 and skip the next, if it is Logic1 (5 Vdc);
call Switch1 ==> if the pin is Logic0 (0 Vdc) then this command will be executed because of the previous.
Then, it will turn on the lights.

Change your hardware, or the simpler way is to change your code to....
btfsc SWPORT, SW1
call Switch1

The situation is the same for the other SWs and also other LEDs

GurkaN

Thank you for your help and advices. I am beginner and every information is useful.
When I press button, 0 V occurs. I have tried it on protoboard and it works. I will
test code and hardware with both situations.

thanks,

regards