Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 16, 2024, 10:08:25 22:08


Login with username, password and session length


Pages: [1]
Print
Author Topic: Code can not display "Hello World"  (Read 4504 times)
0 Members and 1 Guest are viewing this topic.
MicroBox
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 0


« on: September 16, 2011, 03:52:25 15:52 »

Hi, everyone I'm sorry to post this newbie question, but I have my new easypic6 and I'm using PBP2.6. I'm having trouble in displaying text message to an lcd using pic18f4550 at 20Mhz..
Code:
Define OSC 48      ' Core is running at 48MHz

Define LCD_DREG  PORTB
Define LCD_DBIT  4
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG  PORTB
Define LCD_EBIT  5
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

   ADCON1 = 15          ' Set PORTA and PORTE to digital
   Pause 100            ' Wait for LCD to start up

mainloop:
   Lcdout $fe, 1        ' Clear screen
   Pause 500            ' Wait .5 second
   Lcdout "Hello"       ' Display "Hello"
   Pause 500            ' Wait .5 second
   Lcdout $fe, $c0, "World" ' Move to line 2  and display "World"
   Pause 500            ' Wait .5 second
   Goto mainloop            ' Do it forever

   End
I hope someone here can point out what I'm doing wrong..kindly check my connections.

regards,
microbox
Logged
joshua1
Inactive

 Muted
Offline Offline

Posts: 5

Thank You
-Given: 4
-Receive: 2


« Reply #1 on: September 16, 2011, 04:46:44 16:46 »

DEFINE OSC 20

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
Logged
MicroBox
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 0


« Reply #2 on: September 17, 2011, 12:23:54 00:23 »

Hi, thanks for the responce, I tried your suggestions. But still no display on the lcd...hmm I dont know why is not working on pic18f4550, the following code works but using pic16F887 on mikroc
Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "Hello World";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){
  ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 0;

  Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row

  Lcd_Out(2,6,txt4);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row

  Delay_ms(2000);

  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }
}
But I want to use the pic18F4550 and Picbasicpro on the Easypic6 devboard. Sad

Logged
MicroBox
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 0


« Reply #3 on: September 17, 2011, 01:23:52 13:23 »

I modified the config fuse and now runs on 8Mhz  Cool

Code:
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
asm 
    __CONFIG    _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L   
 endasm
 DEFINE OSC 48


   ADCON1 = 15          ' Set PORTA and PORTE to digital
   Pause 100            ' Wait for LCD to start up

mainloop:
   Lcdout $fe, 1        ' Clear screen
   Pause 500            ' Wait .5 second
   Lcdout "Hello"       ' Display "Hello"
   Pause 500            ' Wait .5 second
   Lcdout $fe, $c0, "World" ' Move to line 2  and display "World"
   Pause 500            ' Wait .5 second
   Goto mainloop            ' Do it forever

   End
regards,
microbox
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC