Need help for PIC16C745


Closed Thread
Results 1 to 17 of 17
  1. #1

    Smile Need help for PIC16C745

    Hi everybody,

    I'm using the PIC16C745 microchip to do my final year project
    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 encounter some problem, when i apply the 5 V to the circuit. The Led must Light up, but it did not .
    Here is myCode:

    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
    btfsc 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

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi christina86,
    Certainly I am not the one to ask about assembly language. That said, it looks to me like your sub routines get locked into a loop and never finish their execution.
    example<p>
    ON
    btfsc PORTB,1 ; Has S2 been press? (Normally high,goes low when pressed.)
    goto ON ; No, <font color=red> goto ON and repeats forever</font color>
    movlw b'00000001' ; move it from register 1 to w.
    movwf PORTB ; move it to PORTB to light up the LED<p>
    I think if you wish to recheck the first line you should use whatever assembly equiv. of a for next loop.
    JS
    Last edited by Archangel; - 12th September 2007 at 06:14.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Hi Christina86,

    This is a BASIC language forum ... ASM help is harder to get here. A quick look at your program......

    See Table 4.2 in the 16F745 datasheet. You will see that PORTB resides in BANK0 and TRISB resides in BANK1.

    When you want to work with PORTB, you need to make sure you are in BANK0 (clear RP0 and RP1 in the STATUS register)

    When you want to work with TRISB, you need to make sure you are in BANK1 (set RB0 as you did)

    If you want to continue on and change PORTB values, you need to switch back to BANK0 before updating PORTB (otherwise you will actually update TRISB even though you told the program to update PORTB)

    Code:
    Start 
    	clrf PORTB ; STATUS defaults to BANK0 - clear PORTB output latch  (not really a latch)
    	bsf STATUS, RP0 ; select bank1 
    	movlw b'00000110' ; Set all pins PORTB 1,2 as Input 
    	MOVWF TRISB ; 
    	bcf STATUS, RP0 ; go back to  Bank 0
    The 16C745 appears to be an interesting chip – I hope you are using the windowed version.

    Being that this is a BASIC forum, I should tell you that what you are trying to do would be trivial with PicBasic or PicBasic Pro

    Good Luck
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Hi Joe

    Code:
          btfsc PORTB,1
    this command says "bit test file skip if clear" ... it jumps (skips) over the goto is PORTB.1 = 0
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Exclamation

    Hey Joe,

    I should note that the last time you and I tried to help someone together, we got locked up and whipped ... we better tread carefully here

    http://www.picbasic.co.uk/forum/showthread.php?t=6783
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Hi Paul and Joe,

    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 :
    AIN 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 ; Has S1 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

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

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Is this all of your code or is it a snippet (in post above)? I ask because you have no list, includes, or CONFIG at the start. Inside the Microchip folder (from the MPLAB install), you should be able to find a template for the 16c745. I would suggest using this as the outer shell and put your stuff inside. Further, because the PIC you picked is quite "fancy", you should make it blink an LED first to ensure it is even running. Your program is not difficult, but you should start even simpler than you are otherwise you do not know if your problem is a logic issue, a hardware issue, a register issues, etc.

    Try to blink your led first

    Oh, if your code is complete, you lost the wrap around to return to Start. Your code would just run off into no-where and execute any code left in your PIC (should it be the windowed version)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Hi Paul,

    I did include list and # include and CONFIG in my code .
    list p=16c745 ; list directive to define processor
    #include <p16c745.inc> ; processor specific variable definitions

    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _E4_OSC

    But yet with this, my code is not working.Can you help me. I did like what you said do the simple one first ( blink the LED only ) but it is not working either . Here is my code : for binkling one.
    list p=16c745 ; list directive to define processor
    #include <p16c745.inc> ; processor specific variable definitions

    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _E4_OSC


    MAIN org 00000030h


    bsf STATUS,RP0 ; select bank1
    movlw b'00000000' ; Set pins PORTB 1,2 as Input
    movwf TRISB ;
    bcf STATUS, RP0 ; go back to Bank 0

    Start
    movlw b'00000001' ; move it from register 1 to w.
    movwf PORTB ; move it to PORTB to light up the LED
    movlw b'00000000' ; move it from register 1 to w.
    movwf PORTB ; OFF the LED
    goto Start

    Can you help me with the code cause this Fridat is my dateline.

    Thank you so much

  9. #9
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    >>I did like what you said do the simple one first ( blink the LED only ) but it is not working either
    Did the LED not light or did it stay on?

    What crystal are you using?

    Do you have a schematic?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    Hey Joe,

    I should note that the last time you and I tried to help someone together, we got locked up and whipped ... we better tread carefully here

    http://www.picbasic.co.uk/forum/showthread.php?t=6783
    Yes, We were spanked ! I think this poor kid is going to have to repeat this class, I just looked at the .lst file for a simple "Blinky" and it was 57k file size, I have just downloaded Section 29 from Microchip website.
    Christina, here is a forum from Microchip, where they speak assembly, and apparently C as well.:
    http://forum.microchip.com/tt.aspx?forumid=-2
    Last edited by Archangel; - 13th September 2007 at 08:00.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Thank you Joe for the link.

    HI Paul

    I use the 6 MHZ crystal. I did draw the schematic digram but i do not have a sofware to draw the schematic , so i use free hand.

    Let me expalain how i connect .
    the PIC16C745have 28 pins

    connect pin 8 and 19 to the ground
    pin 20 to +5 V
    pin 21 connnect to a resistor and Led then + 5 V

    pin 21 _______(Resistor)____(Led)___ +5V
    pin 22 connect reisistor ( also the resistor connect to the ground ) + then the switch and follow by + 5V

    (ground)
    ^
    I
    I
    pin 22.______Resistor__(switch)___(+5V)

    pin 23 connect reisistor ( also the resistor connect to the ground ) + then the switch and follow by + 5V


    (ground)
    ^
    I
    I
    pin 23.______Resistor__(switch)___(+5V)

    And the cystal have got 4 pins

    Pin no 7 to the ground
    pin 8 to pin 9 of PIC16C745
    pin 14 to the 5V

    This schematic is tofor match for :

    AIN 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 ; Has S1 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 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

  12. #12
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    You did not answer

    Did the LED light up in your blink test?

    Is your 745 windowed or are you burning new PICs each time?

    On the diode, which end (anode or cathode) is connect to 5V?

    Do you have an Oscilloscope? [EDIT] I have never used a four pin Xtal so I cannot comment on its correctness. If you have a scope, it would be easy to find out.[/EDIT]

    you say "btfsc PORTB,2 ; Has key been press? (Normally high, goes low when pressed.)"
    but you described the opposite - normally low and high when pressed. If it truly is opposite your program flies past this routine and then off into the ether. You would never see the light blink at 24MHz clock speed. You need to have a way to either send the program back to top (e.g., goto START) or a way to stop the controller from running away (e.g., goto $)

    I beg you to make your LED blink first ... the rest is trivial after that.
    Last edited by paul borgmeier; - 13th September 2007 at 09:11. Reason: Add Xtal comment
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  13. #13
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hello,

    I too am not an assembly language user but shouldn't there be some sort of delay (250ms at least)after the LED is turned on and another delay (250ms) after it is turned off so you can actually see the LED changing states?

    BobK

  14. #14
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobK View Post
    Hello,

    I too am not an assembly language user but shouldn't there be some sort of delay (250ms at least)after the LED is turned on and another delay (250ms) after it is turned off so you can actually see the LED changing states?

    BobK
    Yes - that is why I asked

    Did the LED not light or did it stay on?
    without the delays, if the OP's code was working the LED would appear to the eye as stuck on

    I have asked twice.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  15. #15
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default 4 pins crystal

    Just my 2 cents,
    Never seen a 4 pins crystal or resonator, maybe she's using an oscillator, not a crystal.
    Then we should know if the config is right for that.

    BTW Can we use oscillator ???


    Quote Originally Posted by christina86 View Post
    And the cystal have got 4 pins
    Also, maybe someone familiar with this PIC can make a very small program using PBP and send the hex file to Christina to validate the circuit she's using.

    J-P
    Last edited by GrandPa; - 13th September 2007 at 20:56.

  16. #16


    Did you find this post helpful? Yes | No

    Smile

    sorry, it is my mistake. I used the 4 pin using an oscillator.

  17. #17
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Talking Good news!

    Quote Originally Posted by christina86 View Post
    sorry, it is my mistake. I used the 4 pin using an oscillator.
    HeHe!

    I'm happy to know that I helped you find the mistake. The good news is that you learned something you will not forget.I should also tell you that I've seen much worst that that. Ever heard of fried PICs?

    BTW Is the program working fine now?

    J-P
    Last edited by GrandPa; - 14th September 2007 at 04:45.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts