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.

Why can't I pass a value into a function on AVR ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,

Why can't I pass a value into a function on AVR ?

Please have look :
Code:
int lcd_command(char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en(1);
rs(0);
rw(0);
_delay_ms(50);
en(0);
}

I tried : lcd_command(0xFF);

but 0xFF never enter into lcd_data_pin, any ideas ?

Thanks for sharing

- - - Updated - - -

If I tested it without function, it's working :
Code:
	rs(0);
		_delay_ms(100); //delay

		rs(1);
		_delay_ms(100); //delay

        rw(0);
		_delay_ms(100); //delay
		rw(1);
        _delay_ms(100); //delay

		en(0);
		_delay_ms(100); //delay

		en(1);
		_delay_ms(100); //delay

		lcd_data_pin = 0xFF;
		_delay_ms(100); //delay
		lcd_data_pin = 0x00;
Test1.jpg

Any clues ?
thanks
 

Post your fill project files in a zip file. Have you included function prototype and function definition in the Code? Maybe your earlier issue is not solved and thats why it is not working.

To define single bits of Ports you have to use

sbit RS = PORTB.0;
sbit EN = PORTB.1;

#define LCD_PORT PORTC

#define can be used for creating alias for whole PORT and not pins in some Compilers. For pins sbit has to be used in Keil and AVR Studio. In mikroC you can use #define to create alias for PORT pins like

#define RS PORTB.F0
 

Post your fill project files in a zip file. Have you included function prototype and function definition in the Code? Maybe your earlier issue is not solved and thats why it is not working.

To define single bits of Ports you have to use

sbit RS = PORTB.0;
sbit EN = PORTB.1;

#define LCD_PORT PORTC

#define can be used for creating alias for whole PORT and not pins in some Compilers. For pins sbit has to be used in Keil and AVR Studio. In mikroC you can use #define to create alias for PORT pins like

#define RS PORTB.F0

I used AVR studio 4, and please find my attachment included, thank you

- - - Updated - - -

it works on simulatorsimulation.jpg



Code:
#include <avr/io.h>
#include <util/delay.h>

// Define the bits in the port 
typedef struct 
{ 
   unsigned char bit0 : 1, 
                 bit1 : 1, 
                 bit2 : 1, 
                 bit3 : 1, 
                 bit4 : 1, 
                 bit5 : 1, 
                 bit6 : 1, 
                 bit7 : 1; 
} bit_field; 

// Define macro to get the value of each bit 
#define GET_BIT(port) (*(volatile bit_field *) (_SFR_ADDR(port))) 

// Define functions for each bit of the I/O ports in the program 


#define rs  GET_BIT(PORTC).bit0
#define rw  GET_BIT(PORTC).bit1
#define en  GET_BIT(PORTC).bit2
#define data_port PORTD
void test(unsigned char data1);

void test(unsigned char data1)
{
	data_port = data1;
	en = 1;
	_delay_ms(50);
	rs = 0;
	_delay_ms(50);
	rw = 0;
	_delay_ms(80);
	en = 0;
}

int main (void)
{
  	DDRC = 0xFF;
	DDRD = 0xFF;
   while(1)
    {
	
		PORTD = 0x38;
		_delay_ms(50);
		PORTD = 0x01;
		_delay_ms(50);
		/*
		test(0x38);
		_delay_ms(50);
		test(0x01);
        */

    }
}

I tested with
Code:
		PORTD = 0x38;
		_delay_ms(50);
		PORTD = 0x01;
		_delay_ms(50);
it's working but with
Code:
		test(0x38);
		_delay_ms(50);
		test(0x01);

test3.jpg

it's not working......do you have idea ? thanks
 

Attachments

  • Atmega128.zip
    14.7 KB · Views: 70
Last edited:

Show your LCD Connections. If it works in Simulator and not in hardware the problem will be delays in LCD functions and wrong hardware connections. Is you LCD HD44780 Compatible. If not it will not work. Post datasheet of LCD module. Are you using 4-bit or 8-bit LCD mode. Post the high resolution image of LCD module the side which shows pin names or pin numbers.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top