Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What wrong with my C code

Status
Not open for further replies.

smiles

Advanced Member level 4
Joined
Jul 27, 2007
Messages
110
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,096
Here is my beginning code, temporarily stop here when compile error
Code:
void main()
{

   // TODO: USER CODE!!
   // MNEMONICS FOR BUTTONS
   #define   row1   PIN_A0
   #define   row2   PIN_A1
   #define   row3   PIN_A2
   #define   row4   PIN_A3
   #define   col1   PIN_D3
   #define   col2   PIN_D2
   #define   col3   PIN_D1
   #define   col4   PIN_D0
   // MNEMONICS FOR LCD
   #define   lcd_rs   PIN_B0
   #define   lcd_rw   PIN_B1
   #define   lcd_e   PIN_B2
   #define   lcd_cmd_wri   0x00
   #define   lcd_data_wri   0x01
   #define   lcd_set_function   0x30
   #define   lcd_set_visible   0x0E
   #define   lcd_set_mode   0x06
   #define   lcd_set_home_address   0x80
   #define   lcd_clear   0x01

   set_tris_a(0xff);
   set_tris_b(0x00);
   set_tris_c(0x00);
   set_tris_d(0x00);
   output_high(PIN_C0);
   //.........
   //continue.......
   //.........
}
void WriteToLCD(char type,char message)
{
   if(type == "data"){
   output_d(message);
   output_b(lcd_data_wri);
   }
   if(type == "command"){
   output_d(message);
   output_b(lcd_cmd_wri);
   }
   output_high(lcd_e);
   #asm
   nop
   #endasm
   output_low(lcd_e);
}
void InitLCD()
{
   WriteToLCD("command",lcd_set_function);// it says error:attempt to create a pointer to constant, below ones are similar
   WriteToLCD("command",lcd_set_visible);
   WriteToLCD("command",lcd_set_mode);
   WriteToLCD("command",lcd_set_home_address);
}
void ClearLCD()
{
   WriteToLCD("command",lcd_clear);
   WriteToLCD("command",lcd_set_home_address);
}
Could you tell me ways to fix that error or give me ideas to optimize my code, thanks so much !!!
 

hi
i cant see any header file included whcih conatains definitions for the funcitons u r using,such as
set_tris_a(0xff);

Regards
 

The inputs of your WriteToLCD routine are both of type char.

When you invoke your WriteToLCD routine, the first parameter is of char type but your second parameters is a constant "lcd_set_function".
 

the error is simple - you are trying to pass a string ("command") but define it to be a char (void WriteToLCD(char type,char message))

instead of unefficient passing of strings, pass only ONE char, so C for command and D for data. or instead of chars, first define some constant values:
#define command 1
#define data 0
and pass those in your code as short ints

mcs51mc said:
When you invoke your WriteToLCD routine, the first parameter is of char type but your second parameters is a constant "lcd_set_function".
so?

0x41 0x56 0x45!!
 

    smiles

    Points: 2
    Helpful Answer Positive Rating
oh !!! thanks so much :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top