PIC16F88 senior design


Closed Thread
Results 1 to 40 of 72

Hybrid View

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

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

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

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

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

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

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

  8. #8
    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?

  9. #9
    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)

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

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

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 : 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