bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Guys,
Why can't I use a function for this code :
If I use this code, it's running as I want to be
but when I replace to :
I lose the data in "data_port" , does anyone have a clue?
Anyway here's the define :
I'm using AVR Studio 4.
Here's the main loop
Any experiences or ideas will be very appreciated, thank you
Why can't I use a function for this code :
If I use this code, it's running as I want to be
Code:
lcd_ini()
{
data_port(0x30);
//next command
data_port(0x38);
en = 1;
_delay_ms(10);
rs = 0;
_delay_ms(10);
rw = 0;
_delay_ms(100);
en = 0;
_delay_ms(100);
//next command
data_port(0x0F);
en = 1;
_delay_ms(10);
rs = 0;
_delay_ms(10);
rw = 0;
_delay_ms(100);
en = 0;
_delay_ms(100);
//next command
data_port(0x80);
en = 1;
_delay_ms(10);
rs = 0;
_delay_ms(10);
rw = 0;
_delay_ms(100);
en = 0;
_delay_ms(100);
}
but when I replace to :
Code:
lcd_control_comm()
{
_delay_ms(10);
en = 1;
_delay_ms(10);
rs = 0;
_delay_ms(10);
rw = 0;
_delay_ms(100);
en = 0;
_delay_ms(100);
}
lcd_ini()
{
data_port(0x30);
lcd_control_comm()
//next command
data_port(0x0F);
lcd_control_comm()
//next command
data_port(0x80);
lcd_control_comm()
}
I lose the data in "data_port" , does anyone have a clue?
Anyway here's the define :
Code:
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0 PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
uint8_t b1:1;
uint8_t b2:1;
uint8_t b3:1;
uint8_t b4:1;
uint8_t b5:1;
uint8_t b6:1;
uint8_t b7:1; } bits;
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_A (* (volatile bits *) &PORTA)
#define PIN_A (* (volatile bits *) &PINA)
#define DDR_A (* (volatile bits *) &DDRA)
#define PORT_B (* (volatile bits *) &PORTB)
#define PIN_B (* (volatile bits *) &PINB)
#define DDR_B (* (volatile bits *) &DDRB)
#define lcd_data_pin PORTD
#define en PORT_A.b0
#define rs PORT_A.b1
#define rw PORT_A.b2
I'm using AVR Studio 4.
Here's the main loop
Code:
int main (void)
{
DDRA = 0xFF;
DDRD = 0xFF;
while(1)
{
// then you can use specific bits like this to write or read specific bits
lcd_ini();
}
}
Any experiences or ideas will be very appreciated, thank you