Exploring Pic16F628a...


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2008
    Posts
    65

    Smile Exploring Pic16F628a...

    Hello everyone,
    I'm trying to turn On Led1,Led2,Led3 with the Hyperterminal, using pic16F628a. I have this initial code that simply blinks 3 leds. Please guide me on how to configure the bits that enable RX in Rb1 using 4 Mhz internal clock. Please check my initial code below...
    [codes]
    Define OSC 4
    CMCON = 7 ' PortA = digital I/O
    VRCON = 0 ' A/D Voltage reference disabled
    TRISB = %11110000

    PortB = %00000000 ' Turn pins to low state
    Led1 var byte ' Led1 as a byte(8 bits) variable
    myvar var word ' myvar as a word(16 bits) variable

    begin:
    high PortB.0
    pause 100
    low PortB.0
    pause 100
    high PortB.1
    pause 100
    low PortB.1
    pause 100
    high PortB.2
    pause 100
    low PortB.2
    pause 100
    goto begin
    [\codes]

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbox View Post
    I'm trying to turn On Led1,Led2,Led3 with the Hyperterminal, using pic16F628a. I have this initial code that simply blinks 3 leds. Please guide me on how to configure the bits that enable RX in Rb1 using 4 Mhz internal clock. Please check my initial code below...
    Or...you could read the datasheet for the PIC16F628A and pick out the registers you need to set up and try to write some code...
    Or...you could use the SERIN/SERIN2 commands built into PBP and not really have to worry about setting up any USART bits...AND, you wouldn't have to use a level converter (such as a MAX232) to get the right signal levels, since SERIN/SERIN2 can receive 'inverted' RS232 whereas the hardware unit can not...
    Then, after you've written some code, and it does not work, or work in ways you did not anticipate, you post that code here. When that is done, I'm sure a lot of people will jump right in and help you troubleshoot it.

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


    Did you find this post helpful? Yes | No

    Default

    OK you have come back. Here is the config, add this to the top of your code: @ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_on, mclr_on, lvp_off, protect_off 'it is correct, and it most likely will fail to compile, because PBP automaticly adds a default config to your code, which will need to be disabled.<br>
    In your PBP root directory there is a file called 16F628A.inc , open it and add a "<font color=red> ;</font color> " where you see them in the code below which is a copy of that file.
    Code:
    ;****************************************************************
    ;*  16F628A.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2003 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 11/06/03                                        *
    ;*  Version   : 2.45                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F62xA.INC'  ; PM header
            ;device  pic16F628A, xt_osc, wdt_on, mclr_on, lvp_off, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F628A, r = dec, w = -302
            INCLUDE "P16F628A.INC"  ; MPASM  Header
            ;__config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            NOLIST
        endif
            LIST
    After doing this it should compile. All this was necessary because you want to use internal OSC instead of a 4 mhz resonator or crystal, which is what the DEFAULT configs are set up for.
    Last edited by Archangel; - 13th October 2008 at 23:58.
    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.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Joe and MBox

    I remember Mel had released a really nice example of such interfacing ...

    May be she will remind ...

    Alain

    PS : BINGO !


    http://www.picbasic.co.uk/forum/showthread.php?t=573
    Last edited by Acetronics2; - 13th October 2008 at 19:35.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbox View Post
    Hello everyone,
    I'm trying to turn On Led1,Led2,Led3 with the Hyperterminal, using pic16F628a. I have this initial code that simply blinks 3 leds. Please guide me on how to configure the bits that enable RX in Rb1 using 4 Mhz internal clock. Please check my initial code below...
    <font color = red>[codes]</font color>
    Define OSC 4
    CMCON = 7 ' PortA = digital I/O<font color=red> not quite, it means Comparators off.</font color>
    VRCON = 0 ' A/D Voltage reference disabled
    <font color=blue>"lets add this so PortA does not act like a radio antenna and create Ghost problems
    PortA=0
    TRISA=0
    </FONT COLOR>
    TRISB = %11110000 '<font color=green>ports7:4 inputs, ports 3:0, outputs, is that what you want? </font color>

    PortB = %00000000 ' Turn pins to low state<font color=red> Put this before TRISB so when PortB becomes all outputs they initialize in a state set by you, instead of chance</font color>
    Led1 var byte ' Led1 as a byte(8 bits) variable
    myvar var word ' myvar as a word(16 bits) variable

    begin:
    high PortB.0
    pause 100
    low PortB.0
    pause 100
    high PortB.1
    pause 100
    low PortB.1
    pause 100
    high PortB.2
    pause 100
    low PortB.2
    pause 100
    goto begin
    <font color = red>[\codes]</font color>
    Should be CODE not CODES
    <br>
    <b> OH BY THE WAY, Congratulations, you have just written your first successful LED chaser, project using PBP and internal OSC, it works very nicely here.
    Last edited by Archangel; - 14th October 2008 at 01:28.
    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.

  6. #6
    Join Date
    Oct 2008
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile re: exploring pic16f628a

    Hello everyone!
    I appologized the late reply, my computer broke down, had to replace the hard drive. I appreciate to everyone who is helping me alot(specially joe). Anyway this is my updated code.

    [CODE]
    @ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_on, mclr_on, lvp_off
    VRCON = 0 ' A/D Voltage reference disabled
    PortA=0
    TRISA=0
    PortB = %00000000
    TRISB = %11110000
    Led1 var byte
    myvar var word

    begin:
    high PortB.0
    pause 100
    low PortB.0
    pause 100
    high PortB.1
    pause 100
    low PortB.1
    pause 100
    high PortB.2
    pause 100
    low PortB.2
    pause 100
    goto begin

    [\CODE]

    Joe, I followed your intruction to disable the line in the16f628.inc file. No errors when compiled. But before I disabled it, I add the line on top, compiled with no error also.

    thanks in advance,
    mbox
    Last edited by mbox; - 17th October 2008 at 00:49.

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


    Did you find this post helpful? Yes | No

    Default

    But before I disabled it, I add the line on top, compiled with no error also.
    Huh... it should have errored, oh well . . . continuing onward. This lesson we will put some information into those variables and do something based upon the content of those variables.
    Oh and the reason it does not work for you to have code display in a code window is you used a backslash \ it should be a forward slash /, so
    Code:
    @ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_on, mclr_on, lvp_off, protect_off 
    Define OSC 4
    CMCON = 7 ' PortA = digital I/O not quite, it means Comparators off.
    VRCON = 0 ' A/D Voltage reference disabled
    '"lets add this so PortA does not act like a radio antenna and create Ghost problems
    
    PortA=0
    TRISA=%00000111
    
    TRISB = %11110000 'ports7:4 inputs, ports 3:0, outputs, is that what you want?
    
    PortB = %00000000 ' Turn pins to low state Put this before TRISB so when PortB becomes all outputs they initialize in a state set by you, instead of chance
    Led1 var byte     ' Led1 as a byte(8 bits) variable
    myvar var word    ' myvar as a word(16 bits) variable
    start:
    include "modedefs.bas"
    
    
    
    
    
    begin:
    for myvar = 500 to 0 step - 25 ' 500 makes word variable necessary
    high PortB.0
    pause 100
    low PortB.0
    pause 100
    high PortB.1
    pause 100
    low PortB.1
    pause 100
    high PortB.2
    pause 100
    low PortB.2
    pause 100
    'goto begin
    next myvar
    
    main:
    led1 = 4
    '
    if porta.0 = 1 then led1 = 0
    if portA.1 = 1 then led1 = 5
    if PortA.2 = 1 then led1 = 7
    if LED1 < 2 then high portb.0
    if LED1 = 5 then high portB.1
    if LED1 > 5 then high PortB.2
    pause 1000
    portb = 0  ' this turns off the leds
    goto main
    end
    in this code we have all of your previous code so the led chaser will chase for a while then read the PortA lines, and then perfor action based upon the values written in the variables based upon the inputs of portA storing those values into the variables.<br>This code will switch the LEDs upward pretty fast but for reasons I do not yet grasp they switch downward very slowly, but they do switch.<br> Next installment we will send variable information via serial data.
    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.

  8. #8
    Join Date
    Oct 2008
    Posts
    65


    Did you find this post helpful? Yes | No

    Default re:

    Good morning Joe,
    I compiled your updated code with no errors, and it says 183 words used....Running leds from PortB.0-PortB.2. until myvar reached 0 value (very nice).

    On the main label, As you mentioned and as I understand it, if any high value reads on PortA.0-PortA.2 a numeric value on variable Led1 will be assigned and test if the conditions are true to turn on(high) PortB.0 - PortB.2.

    thanks,
    mbox
    Last edited by mbox; - 18th October 2008 at 00:55.

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


    Did you find this post helpful? Yes | No

    Default

    Hi mbox,
    Yep, that's essentially it, now all you have to do is receive some information from outside the PIC, store it in the variables and test IF TRUE. So . . .
    Code:
    serin portA.3,N9600,["A"],Led1 ' pretty much right from the book
    ' reads data from PC data received after "A" stored in LED1 comment out 
    ' PortA IF THEN loops
    Add this to your code and comment out the portA if then loops, send it some data from another PIC or your personal confuser ugh . . . computer and you have what you asked for, what's more, now you understand your code and can make whatever variables and outputs you want.
    Look at BRUCE's website, check these 2 links:
    http://rentron.com/PIC16F84.htm
    http://rentron.com/PicBasic1.htm
    He has lot's of great examples, and he sells stuff too! Highly recommend.
    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.

  10. #10
    Join Date
    Oct 2008
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Good evening Joe,
    Thanks for this helpful tutorial, but I'm not really sure if I doing it right regarding the SERIN command...I tried to simulate it in Proteus software and no result...

    Code:
    @ device pic16F628A, INTRC_OSC_NOCLKOUT, wdt_on, mclr_on, lvp_off 
    Define OSC 4
    CMCON = 7 ' PortA = digital I/O not quite, it means Comparators off.
    VRCON = 0 ' A/D Voltage reference disabled
    '"lets add this so PortA does not act like a radio antenna and create Ghost problems
    
    PortA=0
    TRISA=%00000111
    
    TRISB = %11110000 'ports7:4 inputs, ports 3:0, outputs, is that what you want?
    
    PortB = %00000000 ' Turn pins to low state Put this before TRISB so when PortB becomes all outputs they initialize in a state set by you, instead of chance
    Led1 var byte     ' Led1 as a byte(8 bits) variable
    myvar var word    ' myvar as a word(16 bits) variable
    start:
    include "modedefs.bas"  
    begin:
    for myvar = 500 to 0 step - 25 ' 500 makes word variable necessary
    high PortB.0
    pause 100
    low PortB.0
    pause 100
    high PortB.1
    pause 100
    low PortB.1
    pause 100
    high PortB.2
    pause 100
    low PortB.2
    pause 100
    'goto begin
    next myvar
    PortB = 0 
    main:
    led1 = 4
    loop:
    '*******************************************************
    serin portA.3,N9600,Led1 
      
    if Led1 = 0 then led1 = 1
    if Led1 = 5 then led1 = 5
    if Led1 = 7 then led1 = 7
    if LED1 = 1 then high portb.0
    if LED1 = 5 then high portB.1
    if LED1 > 5 then high PortB.2
    pause 1000
    PortB = 0  ' this turns off the leds
    
    goto loop
    end
    My question is, should I use RB1(TX) as input instead of PORTA.3, because I wanted to use the builtin USUART. and do I need to add any configuration to enable it?

    Thanks in advance,
    mbox

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


    Did you find this post helpful? Yes | No

    Default

    Hserin is always better than serin, works in the background while other code executes as it is hardware based vs bitbang software. I think you are going to need to use a crystal vs intosc because of timing issues especially if you want to use high speed communications, the example I gave you is really too fast for internal OSC, should probably slow it down to something like 300. If you want to use HSERIN you will have to use the appropriate ports, so yes RB1 (RX) as input, there is some code you have to add to use HSERIN too, lots of example code in this forum.
    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.

  12. #12
    Join Date
    Oct 2008
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help Joe appreciate it very much.

    Regards,
    mbox

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Do I need a pause?
    By tazntex in forum Serial
    Replies: 21
    Last Post: - 29th August 2008, 04:32
  3. Help Pic16f628a
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th August 2008, 23:22
  4. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 19:10
  5. Replies: 8
    Last Post: - 22nd July 2008, 20:31

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