Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple PIC Code for Switching - Newbie

Status
Not open for further replies.

devonsc

Advanced Member level 4
Full Member level 1
Joined
Nov 30, 2004
Messages
115
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,931
Hi there,

Help needed badly. Mind helping? Please? Thanks in advance. Regarding the following short PIC code:

My intention is to have a toggle switch that will be switched in two positions and the respective LED will light. Say, switch A, LED A and switch B, LED B. When I run the following program, what I observe is the following:

a.) power up the PIC, switch A on, LED A on, LED B off

b.) power up the PIC, switch B on, LED B on, LED A off

c.) power up the PIC, switch A on, LED A on, LED B off but at this moment, if i were to switch the toggle switch into position B, my LED A remains on while LED B remains off instead of LED B on, LED A off

c.) power up the PIC, switch B on, LED B on, LED A off but at this moment, if i were to switch toggle switch into position A, my LED B remains on while LED A remains off when it is suppose to be LED A on, LED B off

Briefly, it seems that it will only work if I were to turn off the PIC and turn ON the PIC again. It seems that I cant refresh the data input from Port C. Mind to comment about this? Thanks in advance...


------------------------------------------------------

LIST P=16F876
#INCLUDE "P16F876.INC"
__CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_ON
ERRORLEVEL -306, -302

;MAIN PROGRAM 1 - TEST

;*****************************************************

BSF STATUS,RP0
MOVLW B'11000000' ;SW1,SW2,LED1,LED2,*,PWM,*,*
MOVWF TRISC
BCF STATUS,RP0

AGAIN BTFSS PORTC,7
GOTO NEXT
BCF TRISC,4
BSF TRISC,5

NEXT BTFSS PORTC,6
GOTO AGAIN
BCF TRISC,5
BSF TRISC,4
GOTO AGAIN

;*****************************************************

END

----------------------------------------------------------------------------
 

HI,


You need to:
a) set LEDA and reset LEDB when set SW1
B) set LEDB and reset LEDA when set SW2
rigth?

but, when set SW1 and SW2 at the same moment?

Analizing your program I see that you are changing the TRISC, but you need change the PORTC register to change the state of the leds....

your program must be:
AGAIN BTFSS PORTC,7
GOTO NEXT
BCF PORTC,4
BSF PORTC,5

NEXT BTFSS PORTC,6
GOTO AGAIN
BCF PORTC,5
BSF PORTC,4
GOTO AGAIN


In this program when set the SW1 and SW2 at the same moment you will have a hight frequency signal on the both leds...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top