PIC16F88 senior design - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 72 of 72
  1. #41
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Did you set the OSC type in PBP *.inc file for this chip.

    And if you did what did you set it for.

    Or you can do it on this line that I do not see in the new code.

    @ DEVICE MCLR_OFF, PROTECT_OFF, WDT_OFF,_XT_OSC

    Double check the data sheet on this, I do not have it in front of me.
    Dave
    Always wear safety glasses while programming.

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

    Default

    The guy use a 20MHz, so, should be something like HS_OSC instead of XT_OSC.

    Anyways open the M16F88.inc file and enjoy the config fuse list
    Code:
    					; *** DEVICE Fuses Definitions
    EXTRC_OSC_CLKOUT equ    3FEC0013h       ; XX XXXX XXX1 XX11
    EXTRC_OSC_NOCLKOUT equ  3FEC0012h       ; XX XXXX XXX1 XX10
    EXTRC_OSC       equ     3FEC0012h       ; XX XXXX XXX1 XX10
    INTRC_OSC_CLKOUT equ    3FEC0011h       ; XX XXXX XXX1 XX01
    INTRC_OSC_NOCLKOUT equ  3FEC0010h       ; XX XXXX XXX1 XX00
    INTRC_OSC       equ     3FEC0010h       ; XX XXXX XXX1 XX00
    EXTCLK_OSC      equ     3FEC0003h       ; XX XXXX XXX0 XX11
    EC_OSC          equ     3FEC0003h       ; XX XXXX XXX0 XX11
    HS_OSC          equ     3FEC0002h       ; XX XXXX XXX0 XX10
    XT_OSC          equ     3FEC0001h       ; XX XXXX XXX0 XX01
    LP_OSC          equ     3FEC0000h       ; XX XXXX XXX0 XX00
    WDT_ON          equ     3FFB0004h       ; XX XXXX XXXX X1XX
    WDT_OFF         equ     3FFB0000h       ; XX XXXX XXXX X0XX
    PWRT_ON         equ     3FF70000h       ; XX XXXX XXXX 0XXX
    PWRT_OFF        equ     3FF70008h       ; XX XXXX XXXX 1XXX
    MCLR_ON         equ     3FDF0020h       ; XX XXXX XX1X XXXX
    MCLR_OFF        equ     3FDF0000h       ; XX XXXX XX0X XXXX
    BOD_ON          equ     3FBF0040h       ; XX XXXX X1XX XXXX
    BOD_OFF         equ     3FBF0000h       ; XX XXXX X0XX XXXX
    LVP_ON          equ     3F7F0080h       ; XX XXXX 1XXX XXXX
    LVP_OFF         equ     3F7F0000h       ; XX XXXX 0XXX XXXX
    CPD_ON          equ     3EFF0000h       ; XX XXX0 XXXX XXXX
    CPD_OFF         equ     3EFF0100h       ; XX XXX1 XXXX XXXX
    WRT_1FOURTH     equ     39FF0000h       ; XX X00X XXXX XXXX
    WRT_HALF        equ     39FF0200h       ; XX X01X XXXX XXXX
    WRT_3FOURTHS    equ     39FF0400h       ; XX X10X XXXX XXXX
    WRT_OFF         equ     39FF0600h       ; XX X11X XXXX XXXX
    DEBUG_ON        equ     37FF0000h       ; XX 0XXX XXXX XXXX
    DEBUG_OFF       equ     37FF0800h       ; XX 1XXX XXXX XXXX
    CCPMX_ON        equ     2FFF0000h       ; X0 XXXX XXXX XXXX
    CCPMX_OFF       equ     2FFF1000h       ; X1 XXXX XXXX XXXX
    PROTECT_ON      equ     1FFF0000h       ; 0X XXXX XXXX XXXX
    PROTECT_OFF     equ     1FFF2000h       ; 1X XXXX XXXX XXXX
    
    					; *** DEVICE2 Fuses Definitions
    FCMEN_OFF	equ     3FFE0000h       ; XX XXXX XXXX XXX0
    FCMEN_ON	equ     3FFE0001h       ; XX XXXX XXXX XXX1
    IESO_OFF	equ     3FFD0000h       ; XX XXXX XXXX XX0X
    IESO_ON		equ     3FFD0002h       ; XX XXXX XXXX XX1X
    interesting this DEVICE2 option... for those using PM
    Steve

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

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

    Default

    The guy use a 20MHz, so, should be something like HS_OSC instead of XT_OSC.
    My mistake
    Dave
    Always wear safety glasses while programming.

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

    Default

    I know when I was in school, they always made us flow chart out the process first. Would you be able to do something like that for us, because honestly, I'm a little confused by your program.
    some examples...
    Quote Originally Posted by AlaskanEE
    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
    Quote Originally Posted by AlaskanEE
    SERIN PORTA.1,T9600,[inputdata]
    Code:
    'What is the value of inputdata the first time this runs?  If you are using "A" for a qualifier, the statement should be
    SERIN PORTA.1,T9600,["A"],inputdata
    'This statement will wait for until "A" comes in, then puts data after that into variable inputdata
    Quote Originally Posted by AlaskanEE
    IF (X<4) THEN
    Code:
    'I usually write
    IF X<4 THEN
    Did you ever get your hands on a PBP manual?
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  5. #45
    Join Date
    Apr 2007
    Posts
    21

    Default

    I'm trying to get the backlight of my LCD to light when a voltage high is recieved on a pin from a push button circuit. I'm testing to see if I can send A to the LCD screen then have it pause then send a B every time I input a voltage high. The loop works and it sends serial data then pauses then sends serial data then goes back to outputing low voltage till a high is recieved again. The problem is that the LCD just is showing solid squares instead of the leters that I am trying to send. I've looked up the ASCII binary, decimal, and hexadecimal equivolents for A and B and sent the numbers with %, nothing, and $ preceeding the numbers equivolently all with the same result. Here's my code.

    @ DEVICE MCLR_OFF, PROTECT_OFF, WDT_OFF
    INCLUDE "modedefs.bas"
    DEFINE OSC 20
    DEFINE LCD_LINES 2
    ANSEL = %00000000
    TRISB.1 = 0
    TRISB.0 = 1
    WAITLOOP:
    LOW PORTB.1
    if PORTB.0 = 0 then goto waitloop
    IF PORTB.0 = 1 THEN
    serout PORTB.1,T9600,[65]
    pauseus 14000
    serout PORTB.1,T9600,[66]
    ENDIF
    goto WAITLOOP

    this is the code with the decimal notation being used. I don't understand should I just try sending A i.e. serout portb.0,t9600,[A] or is that wrong as well?

  6. #46
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    DEFINE LCD_LINES 2
    If you are using a parallel mode LCD (Hitachi 44780 based), then PBP requires quite a few more defines to get it to work (see the manual).
    If you are using a serial mode LCD (usually a parallel LCD mounted on a PCB with another PIC doing the decoding duties), then the DEFINE shown above isn't going to do anything for you. And you'll want to refer to the manual for the LCD.
    And it would most likely help a lot if we knew what kind of LCD you were using...
    Get the manual! And read it! We can help you with a lot of stuff...but again...I, for one, am not into hand-holding.
    Last edited by skimask; - 25th April 2007 at 23:44.

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

    Default

    OK... now we're on a different subject.

    What type of LCD are you using? If it is a serial LCD, you don't need the following line.
    Code:
    DEFINE LCD_LINES 2
    If it is not a serial display and it has an HD44780 controller, you need some other LCD defines in there. But since I don't know, I'm going to assume it's a serial display. Next the serial part. Try...
    Code:
    serout PORTB.1,T9600,["A"]
    Next, the blocks on the LCD... try adjusting the contrast.

    edit: Looks like Skimask was quicker on the draw. Ignore redundant information from me.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  8. #48
    Join Date
    Apr 2007
    Posts
    21

    Default

    I'm sorry, earlier I copied down my old code that was rittled with errors and didn't have the input and outputs set. Here is the new code:

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

    I want pin A.2 to be the input from the bluesmirf, which will be sending messages to our LCD via serial ports. The serial data will come into the pic through porta.2. Each message that is sent by the bluesmirf will be proceeded by the letter A. I'd like porta.2 to not accept any random data and only activate the loop when a message is recieved that is preceeded by the letter A. The output should be a high then low loop that loops four times. The output should come from portb.2

  9. #49
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    I don't understand should I just try sending A i.e. serout portb.0,t9600,[A] or is that wrong as well?
    Yes, that is also wrong...
    serout portb.0 , t9600 , [ "A" ]
    which is also in the manual...
    Your original line:
    serout portb.0 , t9600 , [ A ]
    will output the value equivalent to the variable A.

  10. #50
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by rhino View Post
    edit: Looks like Skimask was quicker on the draw. Ignore redundant information from me.
    And I was just about to say to ignore redundant information from ME!

  11. #51
    Join Date
    Apr 2007
    Posts
    21

    Default

    The LCD we're using is the serial enabled LCD SerLCD v2.5 it's default settings are 9600 bps with eight bits of data, 1 start bit, 1 stop bit, and no parity. I wasn't sure of the DEFINE LCD_LINES 2 command, but I figured it couldn't hurt since our LCD is 2 lines, and since the LCD is a serial input I didn't think I needed any of the LCDIN/LCDOUT commands.

  12. #52
    Join Date
    Apr 2007
    Posts
    21

    Default

    yeah I forgot the quotes on A. It all made sense in my mind, if you could just stop being selfish and start reading other peoples minds this would be much easier

  13. #53
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    The LCD we're using is the serial enabled LCD SerLCD v2.5 it's default settings are 9600 bps with eight bits of data, 1 start bit, 1 stop bit, and no parity. I wasn't sure of the DEFINE LCD_LINES 2 command, but I figured it couldn't hurt since our LCD is 2 lines, and since the LCD is a serial input I didn't think I needed any of the LCDIN/LCDOUT commands.
    Ok, that's better.
    You've got serout xxxx , t9600 , xxxxx
    Try n9600 instead of t9600 and see what happens. Refer to your LCDs spec's to see which one you actually need.

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

    Default

    Ok, give this a try...
    Code:
    INCLUDE "modedefs.bas"
    DEFINE OSC 20
    ANSEL = %00000000
    INPUTDATA var byte 
    TRISA.2 = 1
    TRISB.2 = 0
    '''''''PORTA.2 = INPUTDATA 'don't need this line
    X VAR BYTE 
    X = 0
    MAIN:
    PORTB.2 = 0
    WAITLOOP:
    SERIN PORTA.2,T9600,["A"],inputdata
    '''''''''''if inputdata <> "A" then goto waitloop ' don't need this line
    LOOP: 
    IF X<4 THEN 
    HIGH PORTB.2 
    PAUSE 2         'Question here... do you really want to pause for 2 milliseconds?
    LOW PORTB.2
    PAUSE 2         'same question here
    X = X+1
    GOTO LOOP
    endif
    goto MAIN
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  15. #55
    Join Date
    Apr 2007
    Posts
    21

    Default

    I made an earlier post asking about that. I'm using an external oscilator set up with a 20MHz oscillator and with the input and out puts going through 47uF capacitors to ground and their perspective input and output oscilator pins on the PIC. When I used PAUSE 500 for a half second pause, it paused for a lot longer than half a second. I lowered it down to 2 and it paused for about a second so I just went with it and just posted a question about it on here

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

    Default

    See post 41 and 42
    Dave
    Always wear safety glasses while programming.

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

    Default

    Quote Originally Posted by AlaskanEE View Post
    I made an earlier post asking about that. I'm using an external oscilator set up with a 20MHz oscillator and with the input and out puts going through 47uF capacitors to ground and their perspective input and output oscilator pins on the PIC. When I used PAUSE 500 for a half second pause, it paused for a lot longer than half a second. I lowered it down to 2 and it paused for about a second so I just went with it and just posted a question about it on here
    I usually use 20pF caps. If you're having that much trouble with the PAUSE statement, I can't for the life of me figure out how the serial timing will ever work. Have you tried 15 (recommended in the datasheet) or 20 pF caps on the oscillator?
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  18. #58
    Join Date
    Apr 2007
    Posts
    21

    Default

    I switched to using the internal oscillator set to 4MHz to see if I could get the pause timing down and it worked. I also switched the serout baud rate setting from t9600 to n9600, but alas I'm still getting random output on the LCD. I'm trying to just get an "A" to appear on the LCD then a 10 second pause then have a "B" appear. This is the code I have:

    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_OFF
    @ DEVICE PIC16F88,PWRT_ON
    @ DEVICE PIC16F88,MCLR_ON
    @ DEVICE PIC16F88,BOD_OFF
    @ DEVICE PIC16F88,LVP_OFF
    @ DEVICE PIC16F88,CPD_OFF
    @ DEVICE PIC16F88,DEBUG_OFF
    @ DEVICE PIC16F88,CCPMX_OFF
    OSCCON = %01100000 '4MHz
    INCLUDE "modedefs.bas"
    ANSEL = %00000000
    TRISB.1 = 0
    TRISB.0 = 1
    WAITLOOP:
    LOW PORTB.1
    if PORTB.0 = 0 then goto waitloop
    IF PORTB.0 = 1 THEN
    serout PORTB.1,N9600,[$41]
    pause 10000
    serout PORTB.1,N9600,[$42]
    ENDIF
    goto WAITLOOP
    end

    the LCD seems to output random charichters but the ones that showed up most offten and in this order where: (). Should I try a different baud rate in my code?

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

    Default Crystal or Clock?

    Hi AlaskanEE,

    If you are going to become an Analog Electrical Engineer this year, you got to get used to the terminology.

    There are “clock oscillators”. These are little circuits that have 4 leads. They need 5 Volts and common supply (input) and have a signal and common output. Generally they are rectangle shaped and have similar pin spacing to a standard IC package with pins only near the corners. The signal output is an acceptable square-wave. These can be used with PIC Microchip. Not very often. These would not use capacitors on the PIC connection.
    And
    There are “crystals”. Crystals are used to help an external (external to the crystal) circuit maintain a “rock solid” frequency. Crystals are used internal to the “clock oscillators”. Crystals are passive devices and generally have two leads. A crystal cannot oscillate without additional components. Some type of active circuit, with positive feedback is usually used. The PIC has all the components needed for oscillating with a crystal. Except, the xxpf capacitors to common, on each crystal lead.

    In light of the above this is difficult to understand:
    Quote Originally Posted by AlaskanEE View Post
    I'm using an external oscilator set up with a 20MHz oscillator and with the input and out puts going through 47uF capacitors to ground and their perspective input and output oscilator pins on the PIC.
    Ohm it's not just a good idea... it's the LAW !

  20. #60
    skimask's Avatar
    skimask Guest

    Default

    Start small and work your way up!
    I don't know how much programming you've done, if you've made a blinky LED, follow a switch, etc.etc.
    The program below should (according to the datasheet) reset the LCD back to defaults (forget about that switch, the backlight, the serial communications, etc.) and just output the alphabet, one character every 1/4 second and repeat itself over and over again...

    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_OFF
    @ DEVICE PIC16F88,PWRT_ON
    @ DEVICE PIC16F88,MCLR_ON
    @ DEVICE PIC16F88,BOD_OFF
    @ DEVICE PIC16F88,LVP_OFF
    @ DEVICE PIC16F88,CPD_OFF
    @ DEVICE PIC16F88,DEBUG_OFF
    @ DEVICE PIC16F88,CCPMX_OFF
    OSCCON = %01100000 '4MHz
    INCLUDE "modedefs.bas"
    ANSEL = %00000000
    TRISB.1 = 0
    TRISB.0 = 1
    dataout var byte

    Waitloop:
    serout portb.1 , n9600 , [ $32 ] 'according to serlcdv2.5 datasheet, should reset LCD back to 9600 (defaults) if it's stuck on some other baud rate

    for dataout = 64 to 89
    serout portb.1 , n9600 , [ dataout ]
    pause 250
    next dataout

    goto waitloop
    end


    Also, according to the datasheet, are you even seeing the 'splashscreen' during power up? If not, you've got other problems. Read the datasheet, you'll see it.

    EDIT:
    I forgot to mention...
    The 4mhz internal oscillator isn't exactly accurate. If you're getting random characters, that might be the reason.
    9600 baud is at the upper end of SEROUT's usability at 4mhz. In this case, it should be ok, but if your 4mhz internal oscillator is a bit low, it might end up being TOO low.
    Last edited by skimask; - 26th April 2007 at 04:14. Reason: Added comments

  21. #61
    Join Date
    Apr 2007
    Posts
    21

    Default

    I've fixed the external oscilator problem, changing out the caps with lower valued ones worked. Now to work on getting the LCD to time corectly output the data. Just to make sure 20MHz should be able to handle a 9600 baude rate without any trouble shouldn't it? Also is there and extra code I need to add to ensure stable operation outside of '@ DEVICE PIC16F88, HS_OSC' and DEFINE 20?

  22. #62
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    I've fixed the external oscilator problem, changing out the caps with lower valued ones worked. Now to work on getting the LCD to time corectly output the data. Just to make sure 20MHz should be able to handle a 9600 baude rate without any trouble shouldn't it? Also is there and extra code I need to add to ensure stable operation outside of '@ DEVICE PIC16F88, HS_OSC' and DEFINE 20?
    20mhz is plenty high to use with 9600 baud (Appendix A of the PBP manual).
    DEFINE 20 is not the correct usage for that DEFINE (Section 4.16)

  23. #63
    Join Date
    Apr 2007
    Posts
    21

    Default

    I know I forgot to put OSC between DEFINE and 20. Anyways here's the code I used trying to get an alphabet output to go through using the 20 MHz external oscillator. the LCD showed a new character every .25 seconds but they were all random characters. Seems like a timing issue to me.

  24. #64
    Join Date
    Apr 2007
    Posts
    21

    Default

    ohh I also tried the original code that skimask used working with the internal oscilator, it gave the same result, successive random symbols and leters.

  25. #65
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    ohh I also tried the original code that skimask used working with the internal oscilator, it gave the same result, successive random symbols and leters.
    Again, generally, random symbols and characters usually mean the baud rate is just a tad too far off. And I know you're not this far, but 'generally speaking' (not a hard fact, but usually accuracte), if the baud rate is a bit slow, you get framing errors, too fast gives overrun errors.

  26. #66
    Join Date
    Apr 2007
    Posts
    21

    Default

    is it possible for me to use a baude rate other than 2400bps or 9600bps?

  27. #67
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by AlaskanEE View Post
    is it possible for me to use a baude rate other than 2400bps or 9600bps?
    Here's a program for you:

    MAIN:
    LCDOUT "See the manual as noted in earlier posts."
    Goto Main

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

    Default

    See the manual as noted in earlier posts.
    Yep.... I think it's time to stop.... take a deep breath.... do a flowchart of what you want this project to do. Draw out a schematic, write your code, then post it all here. There seems to be a lot of jumping around to different problems. We're sixty some posts along now, and I'm not sure if you're making any progress.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

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

    Default

    AlaskanEE -
    Are you still out there?
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  30. #70
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by rhino View Post
    AlaskanEE -
    Are you still out there?
    Maybe he found the manual and, more importantly, read it. And now he's learned so much good stuff, that he doesn't need our help nearly as much anymore.

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

    Smile of course

    Quote Originally Posted by skimask View Post
    Maybe he found the manual and, more importantly, read it. And now he's learned so much good stuff, that he doesn't need our help nearly as much anymore.
    And of course we will now see him, back here helping others!
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  32. #72
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Pic_User View Post
    And of course we will now see him, back here helping others!
    -Adam-
    Exactly what I was thinking.
    Does it work any other way?

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