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.

i need help for PIC16C745

Status
Not open for further replies.

christina86

Newbie level 5
Joined
Sep 10, 2007
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
Hi everybody,

I'm using the PIC16C745 microchip to do my final year project
I have encounter some problem.the situation is,
if switch 1 is pressed, LED will light up and when switch 2 is pressed again, the LED will go off. I am using an assembly language ( sofware MPLab version 7.2) to write the code.
I have succesffuly bulit the code to the PIC16C745 chip, but the led fail to on.
Here is my code :
MAIN org 00000030h

Start
clrf PORTB ; clear PORTB output latch
movlw b'00000000' ; Set all pins PORTB as output
MOVWF TRISB ;

ON
btfsc PORTA,4 ; Has S2 been press? (Normally high,goes low when pressed.)
goto ON ; No, go back check again
movlw b'00000001' ; move it from register 1 to w.
movwf PORTB ; move it to PORTB to light up the LED

OFF
btfsc PORTA,5 ; Has key been press? (Normally high, goes low when pressed.)
goto OFF ; No, check again
movlw b'00000000' ; move it from register 1 to w.
movwf PORTB ; OFF the LED

DebounceA
btfss PORTA,4 ; Has key been released?
goto DebounceA ; No, wait again
goto Start ; Loop again
end ; directive indicates end of code

Can anyone help me with the code weather i have done it correctly and how the circuit will look like ?

Thank you so much !
 

where have you confugured TRISA as input port?

And look,next time copy here the exact program what you have written in your work space.
 

hi cameo_2007 : ) . Thank you so much for replying my post. Uhm, i have just made some amend to the code again. Here is the code :
MAIN org 00000030h

Start
bsf STATUS,RP0 ; select bank1
clrf PORTB ; clear PORTB output latch
movlw b'00000110' ; Set all pins PORTB 1,2 as Input
MOVWF TRISB ;

ON
btfsc PORTB,1 ; Has S2 been press? (Normally high,goes low when pressed.)
goto ON ; No, go back check again
movlw b'00000001' ; move it from register 1 to w.
movwf PORTB ; move it to PORTB to light up the LED

OFF
btfss PORTB,2 ; Has key been press? (Normally high, goes low when pressed.)
goto OFF ; No, check again
movlw b'00000000' ; move it from register 1 to w.
movwf PORTB ; OFF the LED

DebounceA
btfss PORTB,1 ; Has key been released?
goto DebounceA ; No, wait again
goto Start ; Loop again
end ; directive indicates end of code

I use only one port instead to be an input and output. When i build the code inside the PIC16C745, the Led still not turn on. Can you help me to see weather to code i have done correctly. Thank you
 

christina86 said:
OFF
btfss PORTB,2 ; Has key been press? (Normally high, goes low when pressed.)
goto OFF ; No, check again
movlw b'00000000' ; move it from register 1 to w.
movwf PORTB ; OFF the LED

you say it becomes low when the switch is presse,then u need to skip "goto OFF",if the bit is clear.rite?
i mean u need to use btfsc??
 

Dear Cameo,

Thank you so mush for replying my post. I am totally new to this PIC16C745, i have got the project from my teacher which is totaly new to me, it is nothing related to my course of study. I am in the process of learning. Please give me your guidance.
I have made some changes to the code but it is still not working . Can you help me to check?
The code is :
MAIN org 00000030h

Start
bsf STATUS,RP0 ; select bank1
movlw b'00000110' ; Set pins PORTB 1,2 as Input
movwf TRISB ;
bcf STATUS, RP0 ; go back to Bank 0
ON
btfss PORTB,1 ; ( btfss mean it is set to *1* , they will skip to next instruction
goto ON ; No, go back check again
movlw b'00000001' ; move it from register 1 to w.
movwf PORTB ; move it to PORTB to light up the LED

OFF
btfss PORTB,2 ; Has key been press? (Normally high, goes low when pressed.)
goto OFF ; No, check again
movlw b'00000000' ; move it from register 1 to w.
movwf PORTB ; OFF the LED

end ; directive indicates end of code
Thank you so much . I look forward to hearing from you.
 

you have to continously scan the status of your port pins
 

christina86 said:
Dear Cameo,

btfss mean it is set to *1* , they will skip to next instruction

btfss means it will skip the very next instruction if th ebit is set 1

for eg:-
btfss PORTB,1
goto ON
movlw b'00000001'

if port B,1 is set "1", it will skip the line "goto ON". and will execute "movlw" instruction.
 

Is that mean i do it wrong? Can you tell me wihch is the correct way of doing ? Cameo
 

christina86 said:
OFF
btfss PORTB,2

change that to btfsc,and try..still there cud be some more issues.
just check it this in the mean time,let me see the code again.
 

thank you cameo, i will change it and see weather it works.
 

hi Cameo.

i did change the like what you said . BUt the Led is not turning on.

myCOde is :
list p=16c745 ; list directive to define processor
#include <p16c745.inc> ; processor specific variable definitions

__CONFIG _H4_OSC&_WDT_OFF&_PWRTE_OFF&_CP_OFF
Errorlevel-302;

org 0x00000020

Start


bsf STATUS,RP0 ; select bank1
clrf PORTB ;clear PORTB output latch
clrf PORTA ;clear PORTA output latch
movlw b'00000000' ; Set pins as Output
movwf TRISB

movlw b'00000011' ; Set RA0 and RA1 as Input and the Rest is output
movwf TRISA
bcf STATUS,RP0 ; select bank0

ON
btfsc PORTA,0 ;Has S1 been press? (Normally high,goes low when pressed.)
goto ON
bsf PORTB,0 ;turn on RP0 (LED) only;


OFF
btfsc PORTA,1 ;Has S2 been press? (Normally high,goes low when pressed.)
goto OFF
bcf PORTB,0 ;turn off RP0 (LED) only;

goto Start
end

Can you help me
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top