Pic18F452


Closed Thread
Results 1 to 23 of 23

Thread: Pic18F452

  1. #1
    Join Date
    Dec 2005
    Posts
    11

    Default Pic18F452

    Hi iam am trying to use a lcd display using the picbasic pro software the display is working fine using the defult pin setup but when i change the pin configeration using the DEFINES i cant get the display to work.
    can anyone help me out thanks.

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


    Did you find this post helpful? Yes | No

    Default

    That's the equivallent of...

    Question : "My car's broke - can you fix it?"

    Answer : "Sure, bring it in and we'll take a look".

    Inotherwords, post your Defines so we can see them, along with your chip register initialisation... ie if you're using analogue pins your ADCON or CMCON setup, and confirm that if you're using odd hardware pins like PortA.4, you've got a pull-up on it.

  3. #3
    Join Date
    Dec 2005
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie my lcd defines are:
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1
    DEFINE LCD_RWREG PORTE
    DEFINE LCD_RWBIT 2

  4. #4
    MikeTamu's Avatar
    MikeTamu Guest


    Did you find this post helpful? Yes | No

    Default

    If you look at the datasheet, you can see that PortE, bit 0,1, and 2 are all Analog ports. So what is most likely happening, is that the PIC is in analog mode for these pins and not giving you digital outputs.

    Put this in your code before the DEFINES:

    ADCON1.3=0
    ADCON1.2=1
    ADCON1.1=1
    ADCON1.0=0

    These 4 lines will make all of your analog pins into digital pins. If you need to use some of your digital pins as analog ones, then just change these 4 bits according to the table in the datasheet referenced below.

    To see how I came to this, look at page 182 (184 of pdf) in the PIC 18f452 datasheet.

  5. #5
    Join Date
    Dec 2005
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Thank you very much MikeTamu i just assumed that PBP took care of all that for me as there is no reference to it in the pbp manual.

    Thanks again.

  6. #6
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Please Help !

    I am having similar problems trying to get an LCD working on EasyPIC3 from Mikroelectronika Board using PBP and 18F452 MCU. Although i can get the LED to blink , I cannot get the LCD to work. Can you help.

    EasyPIC3 Development Board Configuration -
    D4 - RB4
    D5 - RB5
    D6 - RB6
    D7 - RB7
    RS - RB2
    E - RB3
    RW - GND

    My Code:

    DEFINE OSC 8

    ' HARDWARE DEFINES
    '-----------------------------------------------------------------
    ' Define LCD pins

    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3

    '-----------------------------------------------------------------
    TRISA = %111111 'INITIALIZE PORT DIRECTIONS
    TRISB = %00000000
    TRISC = %10101001
    TRISD = %00000011
    TRISE = %00000111
    Adcon1 = 7 ' Set PORTA DIGITAL
    INTCON2.7=1 ' DISABLE Pull-Up's
    '-----------------------------------------------------------------
    PAUSE 500

    Lcdout $fe , 1 , "EasyPIC3 DEV"
    LCDOut $FE,$C0, "Board v1A"
    PAUSE 2000

    END

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


    Did you find this post helpful? Yes | No

    Default

    Be sure you set HS_OSC fuse before programming your PIC
    Steve

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

  8. #8
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Hello,

    Thanks for coming to my help once again, yes the Crystal fuse is set properly as i have a small led blink rotuine after this display , which works properly.

    The LCD works with MikroBasic Compiler, But does not come on with PBP.

  9. #9
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Because you are running at 8MHz, try including one or both of these and increasing the times as shown here

    DEFINE LCD_COMMANDUS 4000
    DEFINE LCD_DATAUS 100
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  10. #10
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Thank you Steve,

    Hi Steve,

    Your inputs in a different thread solved my problem. The code was OK just that LVP fuse was enabled.

    Just disabled it and there I could see what I had to on my LCD.

    Thanks.

    regards

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


    Did you find this post helpful? Yes | No

    Default

    GOOD!

    Kind of thing to remember i guess!
    Steve

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

  12. #12
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by MikeTamu View Post
    If you look at the datasheet, you can see that PortE, bit 0,1, and 2 are all Analog ports. So what is most likely happening, is that the PIC is in analog mode for these pins and not giving you digital outputs.

    Put this in your code before the DEFINES:

    ADCON1.3=0
    ADCON1.2=1
    ADCON1.1=1
    ADCON1.0=0

    These 4 lines will make all of your analog pins into digital pins. If you need to use some of your digital pins as analog ones, then just change these 4 bits according to the table in the datasheet referenced below.

    To see how I came to this, look at page 182 (184 of pdf) in the PIC 18f452 datasheet.
    Thanks for the clear explanation !
    As you said this will turn all 8 pins into digital.
    Would it be possible to get AN0 and AN1 digital and all the others (AN2 to AN7) analog ?
    It's still unclear in this case what's ADCON0 for !
    Thanks for clearing me out.
    Lotondo

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


    Did you find this post helpful? Yes | No

    Default

    Hava a look in the datasheet, register 17-2, PDF page 184

    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1361&stc=1&d=117069960 6">
    Attached Images Attached Images  
    Steve

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

  14. #14
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Thanks Mr E
    clear enough.
    I believe it's not possible to set the pins like I said
    Could you pls. tell me something more about ADCOM0.
    Datasheets are useful but something they are a little
    too complicate if you are not full into the subject.
    Thanks
    Lotondo

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


    Did you find this post helpful? Yes | No

    Default

    I can't tell anything about ADCOM As it doesn't exist, but let's try with ADCON0

    If you plan to use PBP ADCIN, use my PicMultiCalc software. It make things easy. Let's say your OSC=20 MHz, your analog source impedance is 1K and you want to make a 10 Bit conversion, you need to add those DEFINEs at the top of your code
    Code:
    DEFINE ADC_BITS 10    ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 2    ' ADC clock source  (Fosc/32)
    DEFINE ADC_SAMPLEUS 3 ' ADC sampling time (uSec)
    ADC_CLOCK 2 refer to ADCS1:ADCS0 bits (ADCON0<7:6>)

    Sure you could even use the usual Frc and set your Sampling time to 50uSec and it will cover almost every possible situation.

    Even by using the PicMultiCalc, you'll need to set the ADFM bit in ADCON1 register. Yeah i didn't include this in the software as Microchip change their mind in almost every new PIC. Maybe One day... maybe.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Now, if you plan to NOT use ADCIN, you must do everything manually. Here's ashort example... OK OK it looks huge but...
    Code:
            '
            '   PIC configuration fuses
            '   ========================
            asm
    		__CONFIG    _CONFIG1H, _HS_OSC_1H
                                    ; HS osc (20 MHz
                                    ;		                          
    		__CONFIG    _CONFIG2L, _BOR_ON_2L & _BORV_27_2L & _PWRT_ON_2L 
                                    ; Enable Brown out voltage detect
                                    ; Brown out voltage threshold 2.7 Volt
                                    ;
    		__CONFIG    _CONFIG2H, _WDT_OFF_2H
                                    ; Disable watch dog timer
                                    ;
    		__CONFIG    _CONFIG3H, _CCP2MX_OFF_3H
                                    ; Use default PORTC.1 for CCP2
                                    ;
    		__CONFIG    _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
                                    ; enable stack overflow
                                    ; disable low-voltage programming mode
                                    ; disable background debugger		  
                                    ;
    		__CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L 
                                    ; disable code protect (user block)
                                    ;		                          
    		__CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
                                    ; disable code protect (boot block)
                                    ;		
    		__CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L       
                                    ; disable write protect (user block)
                                    ;		                      
    		__CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
                                    ; disable Write protect CONFIG regs 
                                    ; disable write protect boot block
                                    ; disable rite protect Data EE
                                    ;
    		__CONFIG    _CONFIG7L, _EBTR0_OFF_7L      
                                    ; Disable table Read protect user block
                                    ;
    		__CONFIG    _CONFIG7H, _EBTRB_OFF_7H
                                    ; Disable Read protect boot block enable
            endasm
                    
            '
            '       Hardware configuration
            '       ======================
                    '
            DEFINE OSC 20
                    '
                    '   Adc
                    '   ---
            ADCON0 = %10000001                  ' Conversion clock = Fosc/32             
                                                ' AN0 selected   
                                                ' turn on ADC
    
            ADCON1 = %110001110                 ' right justified results
                                                ' Conversion clock = Fosc/32
                                                ' PORTA.0 as analog, all other to digital
            '
            '       Hardware assignment
            '       ===================
                    '
                    '   LCD
                    '   ---
            DEFINE LCD_DREG PORTD               ' LCD data port 
            DEFINE LCD_DBIT 4                   ' LCD data starting bit 0 or 4 
            DEFINE LCD_RSREG PORTD              ' LCD register select port 
            DEFINE LCD_RSBIT 2                  ' LCD register select bit 
            DEFINE LCD_EREG PORTD               ' LCD enable port 
            DEFINE LCD_EBIT 3                   ' LCD enable bit 
            DEFINE LCD_BITS 4                   ' LCD bus size 4 or 8 
            DEFINE LCD_LINES 2                  ' Number lines on LCD 
            DEFINE LCD_COMMANDUS 2000           ' Command delay time in us 
            DEFINE LCD_DATAUS 50                ' Data delay time in us 
    
            '
            '       Alias definition
            '       ================
                    '
                    '   ADC
                    '   ---
            GoDone  var ADCON0.2                ' use to start/stop/check 
                                                '       AD conversion
                                                
            ADON    VAR ADCON0.0                ' use to start/shut-off ADC
    
            '
            '       Variable definition
            '       ===================
            @AdResult = ADRESL    
            AdResult        var word EXT        ' Store ADC result
            
            '
            '       Software constants
            '       ==================
            ADC_SampleUs    con 3               ' ADC sampling time        
            
            '
            '       Program Start here
            '       ==================
            Pause 500                           ' LCD start up delay
    
    Start:
                    '
                    '       A/D conversion
                    '       --------------
            adon = 1                            ' turn on ADC
            pauseus adc_sampleus                ' Wait minimum sampling time
            godone = 1                          ' start conversion
            while godone : wend                 ' check if finished
                                                '
            adon = 0                            ' turn off ADC
                    '
                    '       Show result on LCD
                    '       ------------------
            lcdout $FE,1, "Result=:", dec adresult 
                                                ' show result on LCD
            pause 250
            goto stART
    Steve

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

  17. #17
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Thanks Mister_E,
    your explanation is well done but it's not easy to get it into
    my head (hard).
    I'll try to make some practical tests.
    I'll take also a look to your prg.
    Regards

    Lotondo

  18. #18
    Join Date
    Jul 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Help Meeeee

    Well, hi everybody ...
    It seems that you all know the basics of how to manage a 2x16 LCD with the famous 18f452 but i don't ..:'(
    I really need to make it work for a project, but here's my problem, i have a pic trainer with the LCD configured to work with the high nibble data bus but it has the RS-->RB2, RE-->RB3 ,R/W-->gnd, and D4-D7 -->RB4-RB7 as you see all in the same portb, i gave on trying it myself. So please could anybody give me a code to display one message on the LCD. I wouldn't mind if you have it for a 16f877 as i have that one too. I know i may be asking too much, but please help me. Thanx
    just in case one of you has mercy on my soul... my email is [email protected]

  19. #19
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default About ADC_CLOCK

    Mister e, you said

    "ADC_CLOCK 2 refer to ADCS1:ADCS0 bits (ADCON0<7:6>)"

    I would like to know where I can find information about this. Or ,maybe easier, can you explain how ADC_CLOCK is "translated" to Focs/32. Is this simply the decimal value of ADCS1:ADCS0 bits?

    Thanks!

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


    Did you find this post helpful? Yes | No

    Default

    GrandPa...

    "ADC_CLOCK 2 refer to ADCS1:ADCS0 bits (ADCON0<7:6>)"

    I would like to know where I can find information about this
    You can find the information you seek and it's all explained in great detail in the DATASHEET for the PIC you are using. Download it from www.microchip.com and study...

    Tip: NEVER program a PIC without first studying it's Datasheet.

    evilpic...

    No, you're not asking too much, but this is very basic stuff that you should be capable of figuring for yourself.

    Take a look at the LCDOUT command located here... http://www.melabs.com/resources/pbpmanual/

    Scroll down until you find the DEFINE statements and change them accordingly for your preferred hardware connections.

    Tip: NEVER program anything without first studying the compiler manual.

  21. #21
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Question Let me explain....

    Thank's Melanie, but I've actually read the datasheet and use it currently. I'm actually setting the ADCON0 register directly instead if using the define.

    My question is very specific about the DEFINE ADC_CLOCK.
    What I don't understand is the meaning of the parameter (number) after the define:

    In the book you have :
    DEFINE ADC_CLOCK 3 'ADC clock source (rc = 3)
    WHY does 3 mean RC clock ?

    And

    Mister e wrote:
    DEFINE ADC_CLOCK 2 ' ADC clock source (Fosc/32)
    Why does 2 mean Fosc/32

    After reading the datasheet, I came to the conclusion that this number is the binary values of ADCS0:ADCS2 (PIC18F4620 here). But I wanted to make sure. So let me ask again:

    ----> Is this the decimal value of ADCS0:ADCS2 ?


    (btw: I'm french, trying my best to explain my question)

    J-P

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


    Did you find this post helpful? Yes | No

    Default

    Yes, whatever you set in DEFINE ADC_CLOCK n, where 'n' is a number between 0 and 7 will reflect in bits ADCS2:ADCS1:ADCS0 as per the table in the PICs DATASHEET that I refered you to..

    If you set a number greater than 7, then only the lowest three bits of your define will be used... ie DEFINE ADC_CLOCK 8 will set ADCS2=0,ADCS1=0 and ADCS0=0.

    I will add, that if you don't specify a DEFINE ADC_CLOCK in your program, the default value if you use ADCIN will be 3 (ie ADCS2=0, ADCS1=1, ADCS0=1).

  23. #23
    Join Date
    Jul 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default hserin..A little help pleeeease!!

    I really need to comunicate a LCD serially with the computer, i'm using the windows hyperterminal to send characters through the RS232 and a MAX232 driver circuit included on my PIC trainer, this is the code i'm using to display those characters on the LCD but all i get is kinda chinese characters or nothing instead of the key i'm pressing... i guess there's something wrong with my hserin but i can't figure what exactly. i'm new to PIC so have mercy on my soul

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9615
    DEFINE HSER_SPBRG 25
    W0 var BYTE

    'Set LCD Data port
    DEFINE LCD_DREG PORTB
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTB
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 2
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTB
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 3
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50
    DEFINE HSER_CLROERR 1 'clear overflow error bit

    pause 500
    Lcdout $fe, 1
    W0=0
    again: HSERIN [ W0 ]
    if W0 = 0 then again
    Pause 500 ' Wait for LCD to startup
    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout W0 ' Display W0
    Pause 500 ' Wait .5 second
    goto again

Similar Threads

  1. PIC18f452 blinking led ?
    By iugmoh in forum General
    Replies: 5
    Last Post: - 7th March 2008, 14:12
  2. Serial communication with pic18f452
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th December 2007, 21:27
  3. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 19:54
  4. Dealy in turn ON of PIC18F452
    By genesis in forum General
    Replies: 1
    Last Post: - 13th October 2006, 10:40
  5. Replies: 5
    Last Post: - 26th March 2006, 19:26

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