PIC16F88 senior design


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 72
  1. #1
    Join Date
    Apr 2007
    Posts
    21

    Question PIC16F88 senior design

    Hi everyone,

    I'm going to have to first state that I am the noob of all noobs. I've never taken any courses on or worked with any sort of programming prior to the senior design project that I'm working on. So in short some of my questions might be really dumb or really simple to answer. I'm programming a 16F88 PIC to complete five basic task for my part of the senior design project. We chose the 16F88 simply because it was used in an earlier lab so we had one on hand and it was the only microcontroler that I had seen any programming done on. The five main task I wish for the PIC to accomplish are as follow:

    1. To simply allow serial data in from a bluesmirf and then directly out to a LCD screen. I would like this to be acomplished using one input pin and one output pin.

    2. When the first bit of serial information is recieved from the bluesmirf, use the first high bit recieved to activate the backlight of the LCD. After 10 seconds the PIC should send the serial data to turn the backlight of the LCD off again. Again I'd like to use one input pin and one output pin.

    3. Again the same serial information should be used to send out a high voltage to be used by an audible alert circuit. The voltage should come out in a half second burst then a half second of low voltage and then repeat 3 times.

    4. A high voltage will be sent to the PIC from a push button switch. This high voltage should cause the PIC to send out the serial data to activate the backlight of the LCD for 10 seconds then turn it off.

    5. The final task for the PIC is to recieve a high voltage from the activation of a warning light LED and then send out a series of high low voltages just like in task three.

    I've written out a code that I thought would work, but it doesn't complete any of the tasks that I want it to. Some basic questions would be, can I use a single input port and a single output port for each of the tasks that I'd like to complete? If so am I assigning the ports right by using TRISA.0 = 1 to set port A.0 to input and TRISB.0 = 0 to set port B.0 to an output? I'm using the SERIN and SEROUT commands to send serial data and I understand the first command after SEROUT is the pin you want to use and the next is the baude rate you're using, but what is the next instruction for and how do I know what to assign to it? Finally can you send hexadecimal commands out of the pic Serially to be understood by the LCD? Below is a copy of the code that I have so far. Any and all help is greatly appriciated.
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352

    Smile

    Hi Alaskan,

    I suggest you go to www.microchip.com and download the datasheet on the 16F88 and learn about the chip. Pay particular attention to the part about analog versus digital I/O and comparators. You need to address these issues before your basic program will work. Also your individual TRIS statements can be setup as TRISA=%00000001 with PortA.0 being an input and the rest of PortA are outputs for example.

    Next I would suggest that you spend a little time looking over this forum at some of the code examples and other peoples problem that are listed to get an idea as to how to write a program and troubleshoot problems. You're off to a decent start, but you can learn alot from this forum.

    There's some great minds on this forum but they won't write your program for you. Don't get us wrong, this is YOUR PROJECT. You have to write it. When you get into a snag then ask for help. BUT the two most important things to have on hand is the PBP manual and the specific datasheet. If you don't have the PBP manual, then goto www.melabs.com and download a copy.

    I've got to go to work now.

    Have a nice day!

    BobK.

  3. #3
    skimask's Avatar
    skimask Guest

    Default

    I'm going to have to first state that I am the noob of all noobs.
    Seems like everybody is...

    So in short some of my questions might be really dumb or really simple to answer.
    Maybe so...but what's really 'dumb' or 'really simple' is when the answer is right in front of you in the little green book.

    I'm programming a 16F88 PIC to complete five basic task for my part of the senior design project.
    Why are these simple projects always part of a 'senior design project'? Senior in high school or senior in college? If senior in college, somebody better get their money back.

    We chose the 16F88 simply because it was used in an earlier lab so we had one on hand and it was the only microcontroler that I had seen any programming done on.
    If this is part of some sort of class, you'd think that there would be resources to possibly use more than a 16F88. But, the 16F88 is a good choice for a simpler project...

    I've written out a code that I thought would work, but it doesn't complete any of the tasks that I want it to. Some basic questions would be, can I use a single input port and a single output port for each of the tasks that I'd like to complete? If so am I assigning the ports right by using TRISA.0 = 1 to set port A.0 to input and TRISB.0 = 0 to set port B.0 to an output? I'm using the SERIN and SEROUT commands to send serial data and I understand the first command after SEROUT is the pin you want to use and the next is the baude rate you're using, but what is the next instruction for and how do I know what to assign to it? Finally can you send hexadecimal commands out of the pic Serially to be understood by the LCD? Below is a copy of the code that I have so far. Any and all help is greatly appriciated.
    Most, if not all, of these questions can be answered by looking in the little green book...

    As far as your code goes...
    DEFINE OSC 20 'SET OSCILATION TO 20MHz
    ------------------Doesn't set the oscillation to 20Mhz. It only tells PBP what you are going to use for an oscillator. It's up to you to get the oscillator to work.

    TRISA.0 = %1 'SETS PORTA.0 AS AN INPUT
    TRISA.1 = %1 'SETS PORTA.1 AS AN INPUT
    TRISA.2 = %1 'SETS PORTA.2 AS AN INPUT
    TRISA.3 = %1 'SETS PORT A.3 TO AN INPUT
    -------------- TRISA=$0F does the same thing....
    -------------- same notes for TRISB

    SERIN SERIAL_INPUT,T9600,[1] 'MAKES PORTA.0 A SERIAL INPUT PORT
    SEROUT SERIAL_OUTPUT,T9600,[1] 'MAKES PORTB.0 A SERIAL OUTPUT PORT
    SEROUT BCKLGHTO,T9600,[1]
    -------------- If you are connected to an actual RS232 port, these won't work too well....

    PAUSE 10
    -------------- Read the little green book to see why this won't work for a 10 second pause...

    LOOP: IF (X<3) THEN 'sends out a high voltage for .5 seconds
    -------------- No real need to put X<3 inside parenthesis, but not a bad idea...



    And to tack onto everything BobK has already said (every bit of which I agree with 100%, except the manual part), we'll help you figure out what's wrong...but we aren't going to write the code for you. Apparently, you're in school to learn, SO LEARN!

  4. #4
    Join Date
    Apr 2007
    Posts
    21

    Default

    I'm not sure what little green book you're refering to. The PICBasic pro program is installed in the school computers, thus there is no manual to look at. I've gone online and looked up the manual so I'm assuming that's what you're refering to. I'm a circuits electrical engineer and thus have never worked with programming or microcontrollers, no classes were ever offered so I'm just learning this simply for my senior design. Keep in mind I'm taking 16 other hours, have a part time job am on two sports teams, and am in multiple organizations on campous so I don't have oodles and oodles of time to devote to reading resources on the subject that I have to look up raondomly on the internet. For senior design they allow your groups to choose a project and run with it, they won't hold your hand anymore so I'm just trying to use the resources out there for help. I know I don't know much about these topics and I've read the PICBasic manual I found online and I've looked through the datasheet, but honestly since I've never had any help or classes on any of this stuff most of what they talk about is beyond me without me spending more time to research the research. Hopefully that helps a bit with where I'm coming from, also despite the preceeding ranting I'm extremly thankfull for the help I've recieved so far on this forum, I know you're using your time to help someone that you don't even know so thank you. I know we're not using RS232 to communicate by the way. So the 16F88 doesn't have it's own internal oscilating crystal. Is there any way to get around creating an external oscilating circuit or is that a must? Also I know PAUSE 10 doesn't pause for ten seconds, I just thought you might need a breif pause between sending the first hexadecimal command to the LCD and the second. Can I just send one right after the other with no break?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Keep in mind I'm taking 16 other hours, have a part time job am on two sports teams, and am in multiple organizations on campous so I don't have oodles and oodles of time to devote to reading resources on the subject that I have to look up raondomly on the internet.
    Are you trying to make us feel sorry for you? It is not working. Ever think about priorities? The time spent playing(sports) could be spent on learning.

    External oscillating circuit is a must. The data sheet gives several examples. I like the crystals with built in caps, one part top do the job and the 20Mhz is cheap.

    I just thought you might need a breif pause between sending the first hexadecimal command to the LCD and the second. Can I just send one right after the other with no break?
    Normally I would say no, but with out knowing exactly which module you are using I can not look up the DATA sheet to give you a good answer.

    Fix the things Shimask pointed out, do some more reading and get back to us if you still need help.
    Dave
    Always wear safety glasses while programming.

  6. #6
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    I'm not sure what little green book you're refering to. The PICBasic pro program is installed in the school computers, thus there is no manual to look at.
    That right there sounds a bit fishy to me...ok...a LOT fishy...

    For senior design they allow your groups to choose a project and run with it, they won't hold your hand anymore so I'm just trying to use the resources out there for help.
    Well, don't expect me (I can't speak for 'us') to hold you hand, but I expect the sentiment is the same.

    I'm extremly thankfull for the help I've recieved so far on this forum
    Thankful doesn't pay the bills...BUT...if you learn, then usually that's enough, 'cause the more you learn, the less you ask.

    So the 16F88 doesn't have it's own internal oscilating crystal.
    It doesn't? Maybe I've got a different version of the 16F88.

  7. #7
    Join Date
    Apr 2007
    Posts
    21

    Default

    The reason there is no green book is because the university bought the lisence for the PICBasic Pro software for only three computers in the lab(the program isn't on any of the other computers), the manual probably is somewhere in the university, but since it's a large campous I'm at a loss to know where it is, simply it's not inside the lab anymore. So if it got missplaced or taken I don't know. Also I am thankful for the help, I was under the impression that this was an open forum for the exchange of ideas and to help those that need help with the knowlege you have. Thus I can only offer my thanks, if this is some form of a forum that requires money I will remove myself so as to no longer leach off of it. Also there have allready been two insults to my university posted, and I truly love my university, please try to avoid using replies that imply my university is sub-par and trying to cheat the system. I mean no disrespect to anyone, I'm just trying to use the resources around me to get this done. The only reason I'm even doing any programming is because no one else in the group wanted to step up, so I did. Programming isn't part of my major, nor have I ever done it, I'm just trying to finish my part. If this forum isn't supposed to be used to ask questions, I'm sorry for my posting I didn't mean to do anything wrong.

  8. #8
    skimask's Avatar
    skimask Guest

    Default

    Whoa...ease up there Sparky...
    Ya gotta figure...somebody comes on-line, asking questions which should be obvious 'cause they're in the manul, says there is no manual, is doing some sort of senior project at a University... Again, it all sounds fishy to me...but that's not the point...
    The posts I've given here are MINE...nobody's else, just mine and only mine. Don't take my 'opinions' as the rules around here. There may be people around here that are a lot more giving than I am, good for them. I look for a bit of 'one hand washes the other' type thing. You ask a question, I give you the answer, hopefully that answer can lead you to other answers, so you don't have to ask as many questions.

    As a 'for instance'...you stated in post #4 that the 16F88 doesn't have an internal oscillating crystal. Well, you would've known that the 16F88 had it's own internal oscillator block that can run at a number of speeds if you'd have read the datasheet, and not even read it, but at least skimmed over it fairly well.
    That's the kind of thing I'm talking about...the blatently obvious question that could've been avoided by the least bit of 'research'. And there ya go...

    So...after you have taken my advice written in post #3 into account and have made some changes to your code. Recompile the code, work the hardware, try it out, and let us know what's up...

  9. #9
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298

    Smile welcome

    Hi AlaskanEE,

    Welcome to the forum.
    Quote Originally Posted by AlaskanEE
    I'm a circuits electrical engineer and thus have never worked with programming or microcontrollers
    You picked the right microcontroller for an analog guy. The PIC devices have comparators, voltage references, A to D converters, etc.. You are going to love these microcontrollers. A perfect fit with the analog world.
    Quote Originally Posted by AlaskanEE View Post
    So the 16F88 doesn't have it's own internal oscilating crystal. Is there any way to get around creating an external oscilating circuit or is that a must?
    You may have based this on what Dave correctly said:
    Quote Originally Posted by mackrackit
    External oscillating circuit is a must. The data sheet gives several examples. I like the crystals with built in caps, one part to do the job and the 20Mhz is cheap.
    The only (out-side the PIC) components needed for the "External oscillating circuit", are a simple three terminal ceramic resonator or a crystal with two capacitors to ground.
    Some of the serial stuff needs a more stable oscillator than the drifty one internal to the PIC. The one in the PIC is okay for a lot of projects.

    Don’t give up on the forum, you are an equal member. Keep asking questions. That’s what it is here for. When a person comes along with a similar question, they won’t have to ask. Don’t forget to search for your question / answer before posting. Have fun. Learn.
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  10. #10
    Join Date
    Apr 2007
    Posts
    21

    Default

    Sorry skimask I was just trying to step gengerly in the forum since I'm new, but was trying to get my point across without ticking anyone off. I know it came off pansy, but I was playing it safe. I misunderstood what you were saying about the internal oscilator. I had skimmed the data sheet and accidentally lumped the statement "the PIC16F88 CAN be set to 20MHz" in with the preceeding paragraph saying that the PIC's internal oscilator can be set to multiple frequencies. So when you said that the DEFINE OSC command doesn't set anything to 20MHz I was confused and the sentance "so the 16F88 doesn't have an internal oscilator" should have had a question mark cause I was asking. Also I was just trying to let everyone know what I'm doing and show the code I was using so that they could comment on what I had done, if it would work or not. I wasn't trying to get everyone to write my code for me and I'm sorry for my lack of clarity on that point. Again sorry for the miscommuniactions and lack of clarity. Also thanks Adam for the suport, I just blew this up too quickly, was getting frustrated with the programming. Chalk it up to experience I guess.

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I should have been a little more clear. If you want something reliable, external oscillator is a must. Being that serial communications are involved. The internals work fine but sometimes the timing will get a little off.

    The oscillator you choose will need to be defined in the *.inc file for the chip you are using along with the other fuses. In the *.bas file you tell PBP what the oscillator speed is for timing. These are the same yet different.

    You will find a line in the *.inc file something like this.

    __config _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_OFF

    Look at the data sheet and it will tell you what each one does.
    Dave
    Always wear safety glasses while programming.

  12. #12
    T.Jackson's Avatar
    T.Jackson Guest

    Default

    Quote Originally Posted by skimask View Post
    Whoa...ease up there Sparky...
    Ya gotta figure...somebody comes on-line, asking questions which should be obvious 'cause they're in the manul, says there is no manual, is doing some sort of senior project at a University... Again, it all sounds fishy to me...but that's not the point...
    The posts I've given here are MINE...nobody's else, just mine and only mine. Don't take my 'opinions' as the rules around here. There may be people around here that are a lot more giving than I am, good for them. I look for a bit of 'one hand washes the other' type thing. You ask a question, I give you the answer, hopefully that answer can lead you to other answers, so you don't have to ask as many questions.

    As a 'for instance'...you stated in post #4 that the 16F88 doesn't have an internal oscillating crystal. Well, you would've known that the 16F88 had it's own internal oscillator block that can run at a number of speeds if you'd have read the datasheet, and not even read it, but at least skimmed over it fairly well.
    That's the kind of thing I'm talking about...the blatently obvious question that could've been avoided by the least bit of 'research'. And there ya go...

    So...after you have taken my advice written in post #3 into account and have made some changes to your code. Recompile the code, work the hardware, try it out, and let us know what's up...
    I'm convinced that someone comes to this forum looking to strike up arguments.

  13. #13
    skimask's Avatar
    skimask Guest

    Cool

    Quote Originally Posted by T.Jackson View Post
    I'm convinced that someone comes to this forum looking to strike up arguments.
    Yep...that's my only function...
    Actually, here's my only function:

    nuffsaid var bit : nuffsaid = 1
    Argument var bit : Argument = 0
    blatentlyobvious var bit : blatentlyobvious = 0

    main:
    argument = 1
    if argument then
    gosub skimask
    endif
    goto main

    skimask:
    blatentlyobvious = nuffsaid
    return

    Any questions?

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Thumbs up

    I think sometimes you might need to use WORD size VAR.

    blatentlyobvious var bit : blatentlyobvious = 0

    Check the DATA sheet, bit is not big enough.
    Dave
    Always wear safety glasses while programming.

  15. #15
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mackrackit View Post
    I think sometimes you might need to use WORD size VAR.
    blatentlyobvious var bit : blatentlyobvious = 0
    Check the DATA sheet, bit is not big enough.
    How 'bout this:
    nuffsaid var bit : nuffsaid = 1 : Argument var bit : Argument = 0
    blatentlyobvious var signed_quad_double_float[10 ^ 100]
    blatentlyobvious = 0

    main:
    argument = 1 : if argument then gosub skimask
    goto main

    skimask:
    blatentlyobvious = 1 / 0
    return

    Now then...how 'bout that new, improved code AlaskanEE?

  16. #16
    Join Date
    Dec 2005
    Posts
    1,073

    Default

    Quote Originally Posted by T.Jackson View Post
    I'm convinced that someone comes to this forum looking to strike up arguments.
    Some forums allow members to create an Ignore List so they don't have to read posts from unhelpful misfits.

  17. #17
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216

    Default

    Quote Originally Posted by skimask View Post
    blatentlyobvious var signed_quad_double_float[10 ^ 100]
    Looks to me like an improper assignment of a variable. Check out page 21 section 4.3 of the little green book and let us know what you find out.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  18. #18
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by rhino View Post
    Looks to me like an improper assignment of a variable. Check out page 21 section 4.3 of the little green book and let us know what you find out.
    Oh, that variable type is in my 'PBP' wish list, and the number of elements in that array are in my 'PIC' wish list.

  19. #19
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by dhouston View Post
    Some forums allow members to create an Ignore List so they don't have to read posts from unhelpful misfits.
    A forum such as this one, yes...
    ...and I would use it...but I don't, and some of the comments, whether pointed at me (or anybody else) directly or indirectly... they amuse me...

  20. #20
    T.Jackson's Avatar
    T.Jackson Guest

    Post

    Quote Originally Posted by dhouston View Post
    Some forums allow members to create an Ignore List so they don't have to read posts from unhelpful misfits.
    What astonishes me the most is how tolerant the admins on this forum are.
    I personally wouldn't put up with some of it.

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

    Default

    Admins don't always have time to read all posts on all threads!

    Let's be nice people - or let me rephrase that - Let's be nice on this forum....

    I know it's tempting to reply to almost every newbie "Read the Manual or Read the Datasheet", I've done it myself to folks - and not just once or twice. It's frustraiting to read some of the posts, especially when there's a 14-page list of what they have to do/achieve and it's coupled with a request for schematics/code/help/complete ready-canned solution for free and the deadline is today lunchtime and they've still got to play a soccer match in the interim - oh, and by the way they haven't got a clue about electronics/programming, they're really a philosophy student that's been landed with the task.

    OK, we've heard it all before! Sometimes it's better not to answer, and people might get the message that they are expected to make some effort themselves too. And if they're really that clueless then a Landscape Gardening project (growing a dwarf Marijuana or similar) is probably a better student option.

  22. #22
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Melanie View Post
    Admins don't always have time to read all posts on all threads!
    With all the spam and viri floating around these days, I'm surprised you have any time to read any of the posts...

    And if they're really that clueless then a Landscape Gardening project (growing a dwarf Marijuana or similar) is probably a better student option.
    Whoa! Where'd that come from?

  23. #23
    Join Date
    Apr 2007
    Posts
    21

    Default

    I thought I might have burnt out my PIC so I started trying very basic commands to test it out. Just output a voltage high on one pin when there's a voltage high on the input pin. This is the code I used:

    DEFINE OSC 8
    TRISA.1 = 1
    TRISA.2 = 0
    LOOP:
    IF PORTA.1 = 1 THEN HIGH PORTA.2
    GOTO LOOP

    END

    I used a VDD of 5V and got an output of 5V at A.2 but sometimes it will suddenly drop to 0 volts without me adjusting anything. I remove the pic from the circuit and then put it straight back in and the output is at 5V again. Sometimes the voltage stays for a while sometimes it goes away rapidly. Does it sound like my PIC might be faulty? or is there a problem in my code. Also if the PIC is outputing a high and I remove the high input I would expect the output to drop as well, but it doesn't. Do I need to include a second IF, THEN statement to achieve this result?

  24. #24
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    DEFINE OSC 8
    TRISA.1 = 1
    TRISA.2 = 0
    LOOP:
    IF PORTA.1 = 1 THEN HIGH PORTA.2
    GOTO LOOP

    END

    Also if the PIC is outputing a high and I remove the high input I would expect the output to drop as well, but it doesn't. Do I need to include a second IF, THEN statement to achieve this result?
    If you read the code inside your 'LOOP', there's nothing there to tell the pin to go low if the input goes low...therefore...

    DEFINE OSC 8
    TRISA.1 = 1
    TRISA.2 = 0
    LOOP:
    PORTA.2 = PORTA.1
    GOTO LOOP

    Also, check your datasheet regarding PortA and analog settings, section 12.0 of the PIC16F88 datasheet. You might see something there that might throw a wrench into your master plan!

  25. #25
    Join Date
    Apr 2007
    Posts
    21

    Default

    I switched up to using B.1 as an input and B.2 as an output along with the portb.1=portb.2 and it worked well. After about 13 seconds, however, it stops working. Is this due to the fact that I'm relying on the internal oscilator or is there additional code that I don't know about. Also I looked over 12.0 and I see that PORT A pins would need additional lines of code to work, but I'm not fully understanding what their saying. Do the pins for PORTA have to be used for A/D conversion?

  26. #26
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    I switched up to using B.1 as an input and B.2 as an output along with the portb.1=portb.2 and it worked well. After about 13 seconds, however, it stops working. Is this due to the fact that I'm relying on the internal oscilator or is there additional code that I don't know about.
    Common stuff:
    Pullup on MCLR to Vdd?
    .1uf cap across Vdd and Vss?
    Power supply solid and smooth?
    WDT config set to Off?

    Also I looked over 12.0 and I see that PORT A pins would need additional lines of code to work, but I'm not fully understanding what their saying. Do the pins for PORTA have to be used for A/D conversion?
    Keep reading past the first couple of paragraphs, read all about the registers relating to the A/D converter and the ports...You'll figure it out.

  27. #27
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216

    Default

    AlaskanEE -
    Hint....
    Read Section 12.0 as Skimasks suggests, review table 12-1. Now go to pg. 52 and review table 5-2. Look at the column that tells you what the POR, BOR and value after all other resets is. What does it tell you about the default setting of the registers in table 12-1?
    Here's another good tool. Use this LINK to search the forums. It seems to work better than the built in search tool.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  28. #28
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Dave
    Always wear safety glasses while programming.

  29. #29
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mackrackit View Post
    These are in the FACT section.
    True that they are FACTs, but don't you mean FAQ section?

  30. #30
    Join Date
    Apr 2007
    Posts
    21

    Default

    So if I want to use an analog input for port A I need to include a line of code such as this:

    ANSEL = %00001111

    if I want PORTA.0-PORTA.3 to be analog inputs, but if I'm getting serial data in through these pins can I keep them as digital input/output ports and just use the first digital high that comes in from the serial information to activate some output on another pin? Also I found a project that used the code 'ADCON1.7 = 1' to align bit 7 to be right justified and then 'ADCON1.4 = 0' and 'ADCON1.5 = 0' to default to using Vref. When I'm not doing any analog to digital conversion I shouldn't need any of these commands should I?

  31. #31
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    So if I want to use an analog input for port A I need to include a line of code such as this:
    ANSEL = %00001111
    if I want PORTA.0-PORTA.3 to be analog inputs, but if I'm getting serial data in through these pins can I keep them as digital input/output ports and just use the first digital high that comes in from the serial information to activate some output on another pin? Also I found a project that used the code 'ADCON1.7 = 1' to align bit 7 to be right justified and then 'ADCON1.4 = 0' and 'ADCON1.5 = 0' to default to using Vref. When I'm not doing any analog to digital conversion I shouldn't need any of these commands should I?
    Basically, the deal is, you have to look at the register's default values (the little numbers above the blocks in the register descriptions in the datasheets). If it says 'R/W-0', then it's a read/write register and on RESET(MCLR), it's set to '0'...and so on...

    So basically, you're on the right track with what you said. I don't have the datasheet handy, you could be right on the bits, if that's what you read, then that's what it is.

  32. #32
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Quote Originally Posted by skimask View Post
    True that they are FACTs, but don't you mean FAQ section?
    Details,Details,Details. FACTs in the FAQ section.

    So if I want to use an analog input for port A I need to include a line of code such as this:

    ANSEL = %00001111
    Check the data sheet for the PIC you are using. I have not used the 16F88 yet, some PICs are a little different.

    if I want PORTA.0-PORTA.3 to be analog inputs, but if I'm getting serial data in through these pins can I keep them as digital input/output ports and just use the first digital high that comes in from the serial information to activate some output on another pin? Also I found a project that used the code 'ADCON1.7 = 1' to align bit 7 to be right justified and then 'ADCON1.4 = 0' and 'ADCON1.5 = 0' to default to using Vref. When I'm not doing any analog to digital conversion I shouldn't need any of these commands should I?
    Something like that.
    Each analog pin can be set to digital or analog.
    If you use serial the pin will have to be set as digital - true.
    If you are not using any analog, set all as digital.

    first digital high that comes in from the serial information to activate some output on another pin?
    NO, serial does not work that way. When a serial signal say XYZ comes in something could be made to happen. If serial ABC comes in something else could happen. If serial QST comes in it could be ignored.

    A digital LOW state is 0 to around 2 volts. Digital HIGH is around 3.6 to 5 volts.

    In between is FUZZY
    Dave
    Always wear safety glasses while programming.

  33. #33
    Join Date
    Apr 2007
    Posts
    21

    Default

    What if I told my partner to have his program send an ASCII character, say, "A" before any message is sent to our bluesmirf which is connected to our LCD through my PIC. Could I use that character to activate a series of commands that would send the correct hexadecimal code to the LCD to activate the backlight then wait 10 seconds then send the code to turn off the backlight? Something like this:

    INCLUDE "modedefs.bas"

    SEROUT PORTB.1,T9600,[1]

    SERIN PORTA.1,T9600,["A"]

    IF PORTA.1 = "A" THEN
    PORTB.1 = $FE
    PORTB.1 = $96
    PAUSE 10000
    PORTB.1 = $FE
    PORTB.1 = $80
    endif

    I'm almost sure that's not right since I'm not sending out serial data just hexadecimal numbers, but can I use the serin/serout commands inside the IF/Then statement? or am I closer than I think.

  34. #34
    skimask's Avatar
    skimask Guest

    Default

    INCLUDE "modedefs.bas"

    SEROUT PORTB.1,T9600,[1]

    SERIN PORTA.1,T9600,["A"] ---- this would only wait for the "A" character, it wouldn't save it anywhere or do anything with it...

    IF PORTA.1 = "A" THEN ---- again, you haven't saved your "A" character anywhere
    PORTB.1 = $FE ---- it's a bit output that you're trying to send a byte out of, that don't work, but I think you already know that...


    What you probably want is:

    INCLUDE "modedefs.bas"
    inputdata var byte
    main:
    SEROUT PORTB.1,T9600,[1] 'trigger something somewhere else
    waitloop:
    SERIN PORTA.1,T9600,[inputdata]
    if inputdata <> "A" then goto waitloop
    serout portb.1,T9600,$FE, $96: pause 10000:serout portb.1,T9600,$FE,$80:goto main
    goto main

  35. #35
    Join Date
    Apr 2007
    Posts
    21

    Default

    I'm now working on sending serial data from our bluesmirf through the pic straight into the serial input port of our LCD. One of my partners currently is working on his java program and has the pic at home so I can't test the code that I have till tomorrow afternoon, but the code I wrote compiles fine and uses a similar format to the code that skimask showed me (baring the backlight activation part).

    @ DEVICE MCLR_OFF, PROTECT_OFF, WDT_OFF
    INCLUDE "modedefs.bas"
    DEFINE LCD_LINES 2
    ANSEL = %00000000
    SERIALDATA var byte
    STORAGE VAR BYTE
    MAIN:
    SEROUT PORTB.0,T9600,[STORAGE]
    SEARCHLOOP:
    SERIN PORTA.0,T9600,[SERIALDATA]
    if SERIALDATA <> "A" then goto SEARCHLOOP
    SERIN PORTA.0,T9600,STORAGE: SEROUT PORTB.0,T9600,[STORAGE]
    GOTO MAIN

    I'm not sure if SERIN, and SEROUT work this way, but what I understand from what I've read and seen is that the serin command will put it's data in the variable byte "STORAGE" that I created and then the SEROUT will send out the serial data that is stored in that variable byte. Does the code look good? Or am I a bit off on my logic. Also I'm not fully sure what the first line does, but I saw it on another project doing serial communication with a PIC16F88 and what I do know about those commands it seems to make sense, it also hasn't hurt anythign I've done so far.

    PS:
    Skimask your smart "S-M-R-T....... I mean S-M-A-R-T" thanks a lot for your help so far.

  36. #36
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    @ DEVICE MCLR_OFF, PROTECT_OFF, WDT_OFF
    Explanations for all those configurations are in the datasheets under 'Special Features' and elsewhere.

    Skimask your smart "S-M-R-T....... I mean S-M-A-R-T" thanks a lot for your help so far.
    Keep in mind, there's literally dozens of people here much more adept with PBP/MPASM, etc.

  37. #37
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216

    Default

    AlaskanEE -
    Don't know if you ever got your hands on a PBP manual, but if you haven't, you can download one from www.melabs.com. Might help with some of those questions regarding syntax.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  38. #38
    Join Date
    Apr 2007
    Posts
    21

    Default

    so the @ symbol tells the programmer that the line is asembly code directly and not PBP code and the other text just activates, or in this case deactivates the features of the PIC that I list. The serin command does store my incoming data into the variable that I put at the end and the serout sends that data that's in the brakets. But I'm worried that since I'm using an exterior 20MHz oscillator (with capacitors from the input of the oscillator to ground and from the ouput of the oscillatorto ground) that the timing might be off. I made a IF/THEN loop that sends a high pauses and sends a low then incraments my variable and will continue till my variable reaches 3 and the pauses were much to long when writen as "PAUSE 500". I thought this would pause 0.5 seconds since I used DEFINE OSC 20, but it didn't, it did however pause for about one second when I set it to "PAUSE 2". Any thoughts?

  39. #39
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    I thought this would pause 0.5 seconds since I used DEFINE OSC 20, but it didn't, it did however pause for about one second when I set it to "PAUSE 2". Any thoughts?
    Show us the whole code again...

  40. #40
    Join Date
    Apr 2007
    Posts
    21

    Default

    Here's the code to activate a loop that incraments the variable x by one each time then stops after x = 4. It's activated when a message has been sent from the blue smirf to the LCD through the pic. My partner precceeds all messages with a capital A to activate the serin command.

    INCLUDE "modedefs.bas"
    DEFINE OSC 20
    INPUTDATA var byte
    X VAR BYTE
    X = 0
    MAIN:
    PORTB.5 = 0
    SEROUT PORTB.1,T9600,[1]
    WAITLOOP:
    SERIN PORTA.1,T9600,[inputdata]
    if inputdata <> "A" then goto waitloop
    LOOP:
    IF (X<4) THEN
    HIGH PORTB.5
    PAUSE 2
    LOW PORTB.2
    PAUSE 2
    X = X+1
    GOTO LOOP
    endif
    goto MAIN

    This is a very simular code that activates the noise alert pulses constantly when the whearer of our device goes out of range then turns off when it comes back in range. It's activated by recieving a low at the input pin.

    DEFINE OSC 20
    TRISB.5 = 0
    TRISB.4 = 1
    X VAR BYTE
    X = 0
    START:
    PORTB.5 = 0
    IF PORTB.4 = 1 THEN GOTO START
    IF PORTB.4 = 0 THEN GOTO LOOP
    LOOP:
    HIGH PORTB.5
    PAUSE 2
    LOW PORTB.5
    Pause 2
    IF PORTB.4 = 1 THEN GOTO START
    GOTO LOOP
    end

Similar Threads

  1. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13
  2. pic16f88 & voltage
    By rdxbam in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th February 2009, 09:14
  3. Ghange code from PIC16F877A to PIC16F88
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th March 2008, 16:09
  4. Replies: 8
    Last Post: - 7th December 2006, 15:42
  5. PIC16F88 problem with TOGGLE command?
    By russman613 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th September 2006, 23: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