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.

[SOLVED] Passing Parameter on ATMEGA128 ?

Status
Not open for further replies.
I tested on ATMEGA 128

it's ok without passing parameter :
Code:
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
   
    
    
    while(1){

 	   lcd_data_pin = 0x30;
   	    _delay_ms(1000);
      en = 1;
	   _delay_ms(500);
	   en = 0;
     
	   _delay_ms(500);

	  lcd_data_pin = 0x38;
   	    _delay_ms(1000);
      en = 1;
	   _delay_ms(500);
	   en = 0;
	 
    }

- - - Updated - - -

I tested on ATMEGA 128

it's ok without passing parameter :
Code:
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
   
    
    
    while(1){

 	   lcd_data_pin = 0x30;
   	    _delay_ms(1000);
      en = 1;
	   _delay_ms(500);
	   en = 0;
     
	   _delay_ms(500);

	  lcd_data_pin = 0x38;
   	    _delay_ms(1000);
      en = 1;
	   _delay_ms(500);
	   en = 0;
	 
    }

- - - Updated - - -

This code can init LCD but can not display character yet, any ideas why ?
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_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
 
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
#define lcd_data_pin PORTA

#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
 




lcd_init()
{
      lcd_data_pin = 0x30;
   	    
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;

//next command
	   _delay_ms(100);
      
	  lcd_data_pin = 0x38;
   	   
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	_delay_ms(100);

      lcd_data_pin = 0x0F;
   	    
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;

//next command
	   _delay_ms(100);
      
	  lcd_data_pin = 0x80;
   	   
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	  
	  } 

void lcd_data()
{
     
       lcd_data_pin = 0x41;// & 0x0F;
     	en=1;
        rs=1;
        rw=0;
        _delay_ms(10);
        en=0;
        
}


 
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
   
    
    lcd_init();
	
    while(1){
      lcd_data();    
    }
    
    return (0);
}
 

Guys,

I can manage until LCD init, but can not display character yet....
any ideas ?
Please see the video :
thanks

- - - Updated - - -

The code :
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_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
 
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
#define lcd_data_pin PORTA

#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
 




lcd_init()
{
      lcd_data_pin = 0x30;
   	    
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;

//next command
	   _delay_ms(100);
      
	  lcd_data_pin = 0x38;
   	   
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	_delay_ms(100);

      lcd_data_pin = 0x0F;
   	    
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;

//next command
	   _delay_ms(100);
      
	  lcd_data_pin = 0x80;
   	   
	   en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	  
	  } 
  lcd_clear()
{
	lcd_data_pin = 0x80;//put the cursor into the first row
     en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	    _delay_ms (300);

	lcd_data_pin = 0xC0;//put the cursor into the first row
     en = 1;
	   rs = 0;
       rw = 0;
	   _delay_ms(10);
      en = 0;
	    _delay_ms (300);

}
void lcd_data()
{
     
       lcd_data_pin = 0x41;// & 0x0F;
     	en=1;
        rs=1;
        rw=0;
        _delay_ms(10);
        en=0;
        
}


 
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
   
    
    lcd_init();
	
    while(1){
        lcd_clear();
      	lcd_data(); 
     
    }
    
    return (0);
}
 
Last edited:

I've got the answer, it's M103C fuse bit, I make it as '1' and program it on ISP programmer, and it's working smoothly now,
Video :
Photo :
Hello ATMEGA128.jpg
Thanks for helping guys...

- - - Updated - - -

Code to share :
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_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
 
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
#define lcd_data_pin PORTA

#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
 

void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
 

void lcd_init(){
    
    lcd_cmd(0x30);
	_delay_ms(100);      
    lcd_cmd(0x38);
	_delay_ms(100);      
    lcd_cmd(0x0F);
	_delay_ms(100);
   	lcd_cmd(0x80);
	_delay_ms(100);

}
 
void lcd_data(unsigned char data1)
{
     
    
    lcd_data_pin = data1;// & 0x0F;
     	en=1;
        rs=1;
        rw=0;
        _delay_ms(10);
        en=0;
        
}
 
void lcd_cmd(unsigned char cmd){
    lcd_data_pin = cmd ;
	    
		en=1;
        rs=0;
        rw=0;
        _delay_ms(10);       
        en=0;
        
}
	

 
void lcd_string(unsigned char *str){
 
    while(*str){
        lcd_data(*str++);       
    }
 
}
 
 
 
 
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
    lcd_init();
    
    
    while(1){
 	  _delay_ms (100);
		lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (100);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (100);
        lcd_cmd(0xC0);//goto second row
        _delay_ms (100); 
       lcd_cmd(0x01); //Clear display
       
	   lcd_string("HELLO ATMEGA128");
	   lcd_cmd(0xC0);//goto second row
       lcd_string("By Riko");
	   _delay_ms(2000);

      
    }
    
    return (0);
}
 

Apart from above issue I am also facing on strange issue in ATMEGA128 board recently.... Here are the seniors -

1) I program the code of blink LED to the ATMEGA128 board with serial programming it get programmed and I dis-connect the USB cable from the PC of the programmer keeping the programmer connector held in the ATMEGA128 socket the code works and I see the blink LED . I had measured the voltage on reset pin is ~ 3v

2) Movement I remove the serial programmer socket from the connecter in the above case the code stop working and I see not led is blinking and if I measure the voltage on reset pin voltage is ~ 5 V

3) I reset the board and measure the voltage on the reset pin voltage is 0 v and leave the reset switch - voltage on reset pin is 5v again but code on the board dose not work...

I am wondering what is happening there....did any body face this issue with ATMEGA128 board... Kindly please note that on my board both JTAG and serial programming connectors are presents .....

please guide me to get the proper working of the code for ATMEGA128 board.....

with regards,

milind
 
Last edited:

Apart from above issue I am also facing on strange issue in ATMEGA128 board recently.... Here are the seniors -

1) I program the code of blink LED to the ATMEGA128 board with serial programming it get programmed and I dis-connect the USB cable from the PC of the programmer keeping the programmer connector held in the ATMEGA128 socket the code works and I see the blink LED . I had measured the voltage on reset pin is ~ 3v

2) Movement I remove the serial programmer socket from the connecter in the above case the code stop working and I see not led is blinking and if I measure the voltage on reset pin voltage is ~ 5 V

3) I reset the board and measure the voltage on the reset pin voltage is 0 v and leave the reset switch - voltage on reset pin is 5v again but code on the board dose not work...

I am wondering what is happening there....did any body face this issue with ATMEGA128 board... Kindly please note that on my board both JTAG and serial programming connectors are presents .....

please guide me to get the proper working of the code for ATMEGA128 board.....

with regards,

milind

may be the code is not uploaded properly to the flash ?

- - - Updated - - -

can I see the reset circuit please ?
 

I am facing the same problem with pic18f87k22

Recently i develop the program for LCD that time i used pic kit3 in debug mode all working fine, but when i program the cpu and remove the pic kit program is running, the moment i reset the cpu LCD gets blank i thought may be the cpu didn't get program correctly i tried for 3-4 times but the problem is same, still i didn't get the answer.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top