16x4 LCD interfacing with dspic30f testing code

Status
Not open for further replies.

P.Copper

Member level 5
Joined
Mar 18, 2013
Messages
82
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,807
Hi all,

I recently bought a 16x4 LCD, can anyone post an LCD code snippet for dspic30f so that i can test whether it is working or not. thanks

i got the below code from microelectronika but when i paste it in my compiler my previous code (for other function) becomes all errors
Code:
[B]program LCD8bitTest[/B][B]
[B]dim txt [B]as string[10]

main:
  ADPCFG = $FFFF [I]' PORTB to be digital
  Lcd8_Init(PORTB, 7, 6, 5, 4, 3, 2, 1, 0, PORTD, 0, 1, 2)
  Lcd8_Cmd(LCD_CURSOR_OFF)
  Lcd8_Cmd(LCD_CLEAR)

  Lcd8_Out(1, 1, "mikroElektronika")
  Lcd8_Out(2, 1, "2x16 LCD Testing") [/I][/B][/B][/B][B][B][B][I][B]end.
[/B][/I][/B][/B][/B]
 

See attached file. This is for dsPIC33 but you can use it with dsPIC30 or any other uC. AD1PCFGL is configured according to dsPIC33. You have to change it according to your dsPIC30 to disable analog input pins. This is LCD4bit code. Compiler used is mikroBasic PRO dsPIC 6.0.0


Code - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
program LCD4bit
 
' LCD module connections
dim LCD_RS as sbit  at LATB0_bit
dim LCD_EN as sbit  at LATB1_bit
dim LCD_D4 as sbit  at LATB2_bit
dim LCD_D5 as sbit  at LATB3_bit
dim LCD_D6 as sbit  at LATB4_bit
dim LCD_D7 as sbit  at LATB5_bit
 
dim LCD_RS_Direction as sbit at TRISB0_bit
dim LCD_EN_Direction as sbit at TRISB1_bit
dim LCD_D4_Direction as sbit at TRISB2_bit
dim LCD_D5_Direction as sbit at TRISB3_bit
dim LCD_D6_Direction as sbit at TRISB4_bit
dim LCD_D7_Direction as sbit at TRISB5_bit
' End LCD module connections
 
' Declarations section 
dim txt1 as char[16]
    txt2 as char[11]
    txt3 as char[8]
    txt4 as char[7]
    i as byte
    
main:
'   Main program 
    txt1 = "mikroElektronika"
    txt2 = "LCD Testing"
    txt3 = "Lcd4bit"
    txt4 = "example"
    
    TRISB = $0000
    PORTB = $0000
    AD1PCFGL = $3FF
    
    Lcd_Init()                       ' Initialize LCD
    Lcd_Cmd(_LCD_CLEAR)              ' Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF)         ' Cursor off
    LCD_Out(1,1,txt1)                ' Write text in first row
    Lcd_Out(2,3,txt2)                ' Write text in second row
    Delay_ms(2000)
    Lcd_Cmd(_LCD_CLEAR)              ' Clear display
    LCD_Out(1,6,txt3)                ' Write text in first row
    LCD_Out(2,6,txt4)                ' Write text in second row
 
    while TRUE                       ' Endless loop
 
    wend
    
end.

 

Attachments

  • dsPIC33_mikroBasic.rar
    41.4 KB · Views: 92
Last edited:


how do i change it to C? i've got no idea how to work with microBasic
 

mikroC PRO dsPIC 6.0.0 code.

You were trying pasting mikroBasic code in mikroC Compiler?



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Lcd module connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB2_bit;
sbit LCD_D5 at LATB3_bit;
sbit LCD_D6 at LATB4_bit;
sbit LCD_D7 at LATB5_bit;
 
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End Lcd module connections
 
unsigned char txt1[] = "mikroElektronika";
unsigned char txt2[] = "LCD Testing";
unsigned char txt3[] = "Lcd4bit";
unsigned char txt4[] = "example";
 
void main(){
 
      TRISB = 0x0000;
      PORTB = 0x0000;
      AD1PCFGL = 0x3FF;
    
      Lcd_Init();                       // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR);              // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);         // Cursor off
      LCD_Out(1,1,txt1);                // Write text in first row
      Lcd_Out(2,3,txt2);                // Write text in second row
      Delay_ms(2000);
      Lcd_Cmd(_LCD_CLEAR);              // Clear display
      LCD_Out(1,6,txt3);                // Write text in first row
      LCD_Out(2,6,txt4);                // Write text in second row
      
      while(1){
             ;
      }
}

 

Attachments

  • dsPIC33_mikroC.rar
    50.4 KB · Views: 85

The code I gave works only with mikroC PRO compiler. You don't have to include any header or c file. In mikroe compiler you just check the LCD library in the library manager. The Compiler will then auto include the LCD library while compiling. I have sent you the whole mikroC PRO dsPIC project files. Open the .mcpds file.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…