Pic16f628 - Pic16f628a


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    7

    Default Pic16f628 - Pic16f628a

    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

  2. #2
    Join Date
    Mar 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Pic16f628 - Pic16f628a

    Hello lester,

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

    thanks

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Mar 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Hello Melanie,

    thank you for your explanation,

    best regards

  5. #5


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Mar 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Hello GurkaN,

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


    Quote Originally Posted by Gurkan-demirbas View Post
    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

Similar Threads

  1. Watchdog Timers
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 18:03
  2. Help Pic16f628a
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th August 2008, 23:22
  3. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 19:10
  4. Need help intergating a PIC16F628 with a DS1307
    By PNightmare in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th October 2007, 19:45
  5. Serout PIC16F628 to PC R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2005, 00:29

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