Exploring Pic16F628a...


Closed Thread
Results 1 to 12 of 12

Hybrid View

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

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

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

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

  5. #5
    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 : 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