How to send 1 bit command into ATMEGA128?

Status
Not open for further replies.

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
Visit site
Activity points
9,442
Guys,
How to send 1 bit command into ATMEGA128?

I tried to send

PORTA.0 = 1;



but the compiler gives me an error.
I got this error :
../main.c:13:1: error: expected ';' before numeric constant


Any ideas ?
thanks
 
Last edited:

Guys,
How to send 1 bit command into ATMEGA128?

I tried to send

PORTA.0 = 1;



but the compiler gives me an error.
I got this error :
../main.c:13:1: error: expected ';' before numeric constant


Any ideas ?
thanks
Assuming that you are using gcc

As I learned somewhere on avrfreak, I use macros add this just below #include
#define SETBIT(x,y) SETBITS((x), (BIT()))

Then use it as
SETBIT(PORTB, 2);
SETBIT(PORTD, 3);

and here are some more macro you will love to see

#define BIT(x) (1 << (x))
#define SETBITS(x,y) ((x) |= )
#define CLEARBITS(x,y) ((x) &= (~))
#define SETBIT(x,y) SETBITS((x), (BIT()))
#define CLEARBIT(x,y) CLEARBITS((x), (BIT()))
#define BITSET(x,y) ((x) & (BIT))
#define BITCLEAR(x,y) !BITSET((x), )
#define BITSSET(x,y) (((x) & ) == )
#define BITSCLEAR(x,y) (((x) & ) == 0)
#define BITVAL(x,y) (((x)>>) & 1)

Hope this help........
 

thanks for replying,

if I want to
#define RS = PORTB.0 ?

how can I do that ?

thanks

- - - Updated - - -

can it be :
#define RS SETBIT(PORTB, 0);
?

thanks

- - - Updated - - -

I'm using AVR studio 4 and c....

- - - Updated - - -

I tried to define like this :

Code:
#define rs(a)  (PORTB = (PORTB & ~_BV(PB0)) | ((a) << PB0))
#define rw(b)  (PORTB = (PORTB & ~_BV(PB1)) | ((b) << PB1))
#define en(c)  (PORTB = (PORTB & ~_BV(PB2)) | ((c) << PB2))

and use it
Code:
rs(0);
delay(1);
rs(1);

am I right on my define ? I can see on simulation but can not see on my logic analyzer ??

- - - Updated - - -

I tried to send :

Code:
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en(1);
rs(0);
rw(0);
_delay_ms(10);
en(0);
}

lcd_command(0x01);

I can't see any response on my logic analyzer, did I miss something here ?
 

I think rs is for LCD, right?
If so, you can define rs to be connected at PORTB 0, but need not to use setbit in define, actually I am also trying to learn and a couple of days away from LCD, give me some time I will dig up google.

OK found that, I am sorry but I have not used atmel studio, have a look at this address

http://winavr.scienceprog.com/example-avr-projects/avr-gcc-4-bit-and-8-bit-lcd-library.html

No need to thanks dear, you can always click helped me button

Gaurav
 
Last edited:

I think the problem is with this line #define RS PORTB.0

I don't know AVR Studio 4. In mikroC we use something like this #define RS PORTB.F0. You have to check some AVR Studio 4 examples which will show how to define a bit.

Also try this

sbit RS = PORTB.0;

RS = 0;
RS = 1;
 

ok I'll try, it looks like in MCS51 on keil with sbit...

- - - Updated - - -

should be like this : #define lcd_data_pin = PORTD, I missed "="

thanks
 

I got the answer https://www.edaboard.com/blog/861/

- - - Updated - - -

it's not working by the time I send en = 1
Please find the code attached

- - - Updated - - -

I tested outside the function, it's working:
Code:
 while(1)
    {
	   en = 0;
	   _delay_ms(30);
	   en = 1;	
	   _delay_ms(30);
       rs = 0;
	   _delay_ms(30);
	   rs = 1;	
	   _delay_ms(30);
       rw = 0;
	   _delay_ms(30);
	   rw = 1;
 

Attachments

  • Atmega128.zip
    18.5 KB · Views: 122
Please see the screen shot :


- - - Updated - - -

sbit RS at PORTB.0;
I got error with that line...

- - - Updated - - -

I struggle with these codes and it seems that there's no response, anybody has ideas ?
Code:
#include <avr/io.h>
#include <util/delay.h>


 //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)
 
int main (void)
{
  	
	DDRA = 0xFF;
	//lcd_ini();
  while(1)
    {
	    PORT_A.b0 = 0;
		_delay_ms(50);
		PORT_A.b0 = 1;
	
	
        

    }
}
 

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…