Need help for PIC16C745


Closed Thread
Results 1 to 17 of 17

Hybrid View

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

Members who have read this thread : 0

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