help with PIC 16f877


Closed Thread
Results 1 to 13 of 13
  1. #1
    naffets_23's Avatar
    naffets_23 Guest

    Default help with PIC 16f877

    hey

    i'm new with the 16f877 and im workin on a project with respect to it and i'm looking for a piece of code where the PIC takes 8 inputs from switches and wen one of these switches are on, it outputs 8 bits to a parallel port on a computer

    if any of you can help me, it would be greatly appreciated


    also, if it is not too much, can i get an idea of what the schematic would look like

    thanks

  2. #2
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Talking Hi i am new too :) But i can help u a little...

    'for buttons
    loop:
    if portb.0=0 then goto b1
    if portb.1=0 then goto b2
    if portb.2=0 then goto b3
    if portb.3=0 then goto b4
    if portb.4=0 then goto b5
    if portb.5=0 then goto b6
    if portb.6=0 then goto b7
    if portb.7=0 then goto b8
    goto loop

    'for actions
    b1:
    high portd.0
    gosub bekle
    goto loop

    b2:
    high portd.1
    gosub bekle
    goto loop

    b3:
    high portd.2
    gosub bekle
    goto loop

    b4:
    high portd.3
    gosub bekle
    goto loop

    b5:
    high portd.4
    gosub bekle
    goto loop

    b6:
    high portd.5
    gosub bekle
    goto loop

    b7:
    high portd.6
    gosub bekle
    goto loop

    b8:
    high portd.7
    gosub bekle
    goto loop

    bekle:
    pause 1000
    RETURN

    end
    Asking is not a shame but not learning is a SHAME!!!

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    TRISB=255
    TRISD=0
    OPTION_REG.7=0 ' enable pull-ups resistor on PORTB
    Loop:
        PORTD=~PORTB
        goto Loop
    Connect your switchs between PORTB and GND.
    All PORTD pins goes to PC thru serie resistor.. let's say 1K
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Nafetts.

    Can't test this code, but it can be used as Psuedo...

    TRISB="11111111"
    TRISD="00000000"

    main:
    Portd=0
    If Portb.0=1 then Portd=1
    if Portb.1=1 then Portd=Portd+2
    If Portb.2=1 then Portd=Portd+4
    if Portb.3=1 then POrtd=Portd+8
    if Portb.4=1 then Portd=Portd+16
    if Portb.5=1 then POrtd=Portd+32
    if Portb.6=1 then POrtd=Portd+64
    if Portb.7=1 then portd=Portd+128

    Pause 1000 (pause 1 second)
    goto main
    end

    I believe there is a way to access this through a loop,
    but I dont' have my PBP with me to give you proper code.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    naffets_23's Avatar
    naffets_23 Guest


    Did you find this post helpful? Yes | No

    Default

    ok thanks alot...i would try these programs out either tomorrow or sometime else this week

  6. #6
    naffets_23's Avatar
    naffets_23 Guest


    Did you find this post helpful? Yes | No

    Default

    ok
    well our instructor decided to change the school project to using serial instead of parallel communication

    i am using pic code for the first time and im not sure how to get the pic to capture the input from the 8 switches and output it.

    which ports on the pic do i use?
    because when i was checking out the pic schematic, all the ports could be programmed ?!

    how do u determine which ports to use and how would u modify the code that SuB-ZeRo gave me for serial?? (thank u very much for ur help SuB-ZeRo)

    finally, how do u setup the baud rate??

    let me explain
    the pic takes the input from the switches and outputs to the serial port on the computer
    if i setup the pc's com port to use a baud rate of 9600... how do i setup the pic to output at that baud rate?

    please keep in mind, i have never used a pic before but that doesnt mean that u cant throw some moderate code at me... just that ill ask questions later!

    thanks for all ur help
    Last edited by naffets_23; - 16th July 2005 at 20:21.

  7. #7
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default yo

    yo dude are you sure it is to be done in picbasic? just double checking.

    get a picbasic manual and read up on the serout and serin commands. itll give you syntax plus an example. it tells baud and other info

    also, check out this site that shows how to serially communicate to a visual basic program and a pic. cool stuff.

    http://www.rentron.com/VisualBasic.htm

    also most of the code ideas above are just ideas dude, not to be copy and pasted into your project.

    you use the ports that best suit your application. meaning dont use the anologue ports(if any) when there are free descrete ones. try and use some logic in choosing your ports. like, put all the buttons on one port and other devices on a different one or someting.

    also, im not 100% but i think that you going to have to use a MAX232 or similar device to be able to comunicate wit the pc, not sure though. you can still generate serial data without one.

    also need to wire your buttons up properly so there is no false triggering.

    check out the schematics section of this forum. yo gonna need to take bits of data from different sources and add them together to suite your needs. its not all gonna be laid out in front of you.

  8. #8
    Depot1's Avatar
    Depot1 Guest


    Did you find this post helpful? Yes | No

    Default Qbasic to PBP on pic16F876 check my code

    i'm trying to get Qbasic and the 16F876 pic to Talk
    VIA RS232 and the Max232 chip
    if i start the pic first -nothing happens
    if i start QB first then pic i get "Device I/O error" message
    .5 sec after pic is started
    qbasic may work at 19200 baud which i would like
    and i think i would need faster that
    4mhz crystal for the pic also

    ---------------------------------
    PBP code here-
    ---------
    DEFINE LOADER_USED 1 'for melabs bootloader
    DEFINE OSC 4 'for 20mhz pic
    DEFINE HSER_RCSTA 90h 'set port to input
    DEFINE HSER_TXSTA 20h 'set port to output
    DEFINE HSER_BAUD 9600 'set baud rate
    B0 VAR BYTE
    B1 VAR BYTE
    B1 = 44
    B0 = 0
    Hseer: HSerout [B1]
    HSerin [B0]
    IF B0 > 0 Then loop 'go to loop and blink led if value found
    GoTo hseer
    loop: High 0 'Turn on LED connected to RB0
    Pause 50 'Delay for .5 seconds
    Low 0 'Turn off LED connected to RB0
    Pause 50 'Delay for .5 seconds
    GoTo loop 'Go back to loop and blink LED forever
    End
    -------------------------end PBP code
    Qbasic-code below
    -----------------
    10 CLS
    ' Open communications (2400 baud, no parity, 8-bit data,
    ' 1 stop bit,
    OPEN "COM1:9600,N,8,1,CD0,CS0,DS0,OP0" FOR RANDOM AS #1
    20 INPUT #1, B$
    PRINT B$
    30 GOTO 20
    END

    -----------------
    Qbasic Loop test works fine
    ---- looptest.bas
    10 CLS
    ' Open communications (9600 baud, no parity,
    ' 8-bit data,1 stop bit,
    OPEN "COM1:9600,N,8,1,CD0,CS0,DS0,OP0" FOR RANDOM AS #1
    20 A$ = "Hello"
    Print #1, A$
    INPUT #1, B$
    PRINT B$
    30 GOTO 30 'holds screen
    END

  9. #9
    Depot1's Avatar
    Depot1 Guest


    Did you find this post helpful? Yes | No

    Default Help with subscribe picbasic list

    the pic basic list
    has been around for long time
    they have lots of knowledge
    but when send email
    Subscribe picbasic-l
    i get no responce
    please help

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i'm not going trough the Qbasic code since it's really far in my mind but to do a efficient 9600 bauds comm with a 4MHZ crystal you should redefine you USART like...
    Code:
    DEFINE HSER_RCSTA 90h 'set port to input
    DEFINE HSER_TXSTA 24h 'set port to output <=== BRGH=1
    DEFINE HSER_BAUD 9600 'set baud rate
    this will gives you a better error % (0.16% against ~7% with 20h)

    Another method to check you serial communication will be to use the serial communication windows of MicroCode Studio. Easy to use, work really good and there's one free version
    Download here
    Once you're sure that your serial communication work.. do your VB or Qbasic code
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    I'd like to add that if your instructor has set you a project, then it's unfair to come on the forum and ask for a solution. Start by reading your PICBasic manual and your QBASIC manual. You'll have learnt nothing if we gave you all the answers. In the case of Depot1 (who's obviously on the same course), take a look at your comments and compare with your code - they don't even match... just a few examples...

    DEFINE OSC 4 'for 20mhz pic ... really? So the number 4 means 20MHz?

    Pause 50 'Delay for .5 seconds ... close but no cigar!

    HSerin [B0] ... and you wonder why your PIC is hanging...

    Open communications (2400 baud, no parity, 8-bit data,
    ' 1 stop bit,
    OPEN "COM1:9600,N,8,1,CD0,CS0,DS0,OP0" FOR RANDOM AS #1

    Well, is it supposed to be 2400 or 9600 ?

    Did you write this or copy it from someone? If we help you graduate, how long would you last when you got a real job.

    Read the Manuals... and compare the commands to what you've written (or copied). Please guys, no Private Messages, I'm not going to do your homework or sit your exams for you.

  12. #12
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default Homework

    I'd just like to add to Melanie's comments,

    Instructors have computers and can look at posts on lists too!

    Robert G8RPI.

  13. #13
    Depot1's Avatar
    Depot1 Guest


    Did you find this post helpful? Yes | No

    Default My post clearified here

    first off there is no exam and it is not for school
    it's my personal work
    there is a define for 4 mhz because
    i am using a 20 mhz pic,
    at 20mhz they do not run stable
    do you know what this define is used for ?
    the Hserout is before Hserin
    i turn on PIC wait to see if something is sent
    if it hangs it's afterwards not before
    and there is no "pause 50"
    unless you see it in some of the comments they do nothing
    they are from a program that i started with then rewrote it
    perhaps i should have took them out
    and i should cleaned up the codes before posting
    sorry for the sloppy mess

Similar Threads

  1. SPI Communication between two pic 16f877
    By anti83 in forum Serial
    Replies: 1
    Last Post: - 5th July 2008, 21:06
  2. serial communication between CMUcam and PIC 16F877
    By gengkeys in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th March 2007, 06:43
  3. pic 16f877 iel kayan yazı
    By bedir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th January 2007, 07:10
  4. Use the PIC 16f877 or 877A instead of shift registers.
    By tsanders in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2006, 17:23
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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