Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

pic18f1220 and PORTB (digital)

Alex
2007-04-22
2013-03-12
  • Alex
    Alex
    2007-04-22

    Hello,this code work well:

    #include <pic18fregs.h>

    code char at __CONFIG1H CONFIG1H = 0x08; //internal
    code char at __CONFIG2L CONFIG2L = 0x00; //PWRT
    code char at __CONFIG2H CONFIG2H = 0x00; //WDT off
    code char at __CONFIG3H CONFIG3H = 0x00; //MCLRE off
    code char at __CONFIG4L CONFIG4L = 0x80; //all off

    void main(void)
    {
        PORTB = 0;
        ADCON1 = 0x70;
        TRISB = 0;
        PORTBbits.RB1 = 1;
        PORTBbits.RB3 = 1;
        PORTBbits.RB5 = 1;
        PORTBbits.RB7 = 1;
        while(1);
    }

    RB1 RB3 RB5 and RB7 set up correctly.

    This one doesn't work at all (RB3 doesn't turn on):

    #include <pic18fregs.h>
    #include "delaymod.h"
    #include "lcd.c"

    code char at __CONFIG1H CONFIG1H = 0x08; //internal
    code char at __CONFIG2L CONFIG2L = 0x00; //PWRT
    code char at __CONFIG2H CONFIG2H = 0x00; //WDT off
    code char at __CONFIG3H CONFIG3H = 0x00; //MCLRE off
    code char at __CONFIG4L CONFIG4L = 0x80; //tutto off

    void main(void)
    {
        PORTB = 0;
        ADCON1 = 0x70;
        TRISB = 0;
        PORTBbits.RB3 = 1;
        DelayMs(100);            // serve per stabilizzare l'alimentazione dell'lcd (l'lcd è molto lento)
        LCD_INIT();            // INDISPENSABILE serve ad inizializzare l'LCD
        DelayMs(250);            // piccolo ritardo per completare l'inizializzazione (facoltativo)
        LCD_CLEAR();            // Cancella il display
        DelayUs(200);            // Altra piccola pausa (facoltativo)
        LCD_CMD(LCD_line1);        //qui dico che devo cominciare a scrivere dal primo carattere del primo rigo
        LCD_PUTS("Ciao Alex!!!");    // ecco come si mette una stringa di caratteri
        while(1);
    }

    why?I think it's very strange..
    All files are there: http://cyberalexgm.altervista.org/lcd.tar.gz