AVR128DA48 PORTC WORKS WITH LCD BUT NOT with CUSTOMISED PINS.

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there, I am using AVR128DA48 nano card for LCD 20X4 JHD204A. The connections are proper. when i use C port. LCD works fine shows charactors. but to use usart I am using E0-E3,F2-F5 for 8 bit bus.

now it isnot showing anything.

#define F_CPU           4000000UL  /* Main clock frequency */

#include <xc.h>
#include <util/delay.h>
#include <string.h>
#include <avr/cpufunc.h>
#define D_I_SET   PORTB_OUT |= PIN0_bm
#define D_I_RESET PORTB_OUT &= ~PIN0_bm
#define R_W_SET   PORTB_OUT |= PIN1_bm
#define R_W_RESET   PORTB_OUT &= ~PIN1_bm
#define E_SET       PORTB_OUT |= PIN2_bm
#define E_RESET     PORTB_OUT &= ~PIN2_bm
#define D0_SET         PORTE_OUT |= PIN0_bm
#define D1_SET        PORTE_OUT |= PIN1_bm
#define D2_SET         PORTE_OUT |= PIN2_bm
#define D3_SET        PORTE_OUT |= PIN3_bm
#define D4_SET         PORTF_OUT |= PIN2_bm
#define D5_SET        PORTF_OUT |= PIN3_bm
#define D6_SET         PORTF_OUT |= PIN4_bm
#define D7_SET        PORTF_OUT |= PIN5_bm
#define D0_RESET         PORTE_OUT &= ~PIN0_bm
#define D1_RESET        PORTE_OUT &= ~PIN1_bm
#define D2_RESET         PORTE_OUT &= ~PIN2_bm
#define D3_RESET        PORTE_OUT &= ~PIN3_bm
#define D4_RESET         PORTF_OUT &= ~PIN2_bm
#define D5_RESET        PORTF_OUT &= ~PIN3_bm
#define D6_RESET         PORTF_OUT &= ~PIN4_bm
#define D7_RESET        PORTF_OUT &= ~PIN5_bm
void curser(uint8_t set);
void command(char i);
void write(char i);
void init();
static void PORT_init(void);
void set_curser(uint8_t set);
void CLKCTRL_init(void);
void DisplayRow (int row,const char *str);

void data(char c);

int num[10];
void curser(uint8_t set)
{
	command(0x02);
	_delay_ms(2);
	command (set);
	_delay_ms(2);
}
void command(char i)
{
	//P1 = i; //put data on output Port
	data(i);
	_delay_ms(1);
	D_I_RESET; //D/I=LOW : send instruction
	R_W_RESET; //R/W=LOW : Write
	E_SET;
	_delay_ms(1); //enable pulse width >= 300ns
	E_RESET; //Clock enable: falling edge
	//P1 = 0;
	//R_W_SET;
}
/**********************************************************/

void write(char i)
{
	//P1 = i; //put data on output Port
	data(i);
	_delay_ms(1);
	D_I_SET; //D/I=HIGH : send data
	R_W_RESET; //R/W=LOW : Write
	E_SET;
	_delay_ms(1); //enable pulse width >= 300ns
	E_RESET; //Clock enable: falling edge
	//P1 = 0;
//	D_I_RESET;
//	_delay_ms(1);
//	P1 = 0;
	//R_W_SET;
	//NVMCTRL.CTRLA;
}
/**********************************************************/
void init()
{
	//P1 = 0;
	data(0);
	_delay_ms(1);
	E_RESET;
	_delay_ms(100); //Wait >40 msec after power is applied
	command(0x30); //command 0x30 = Wake up
	_delay_ms(30); //must wait 5ms, busy flag not available
	command(0x30); //command 0x30 = Wake up #2
	_delay_ms(10); //must wait 160us, busy flag not available
	command(0x30); //command 0x30 = Wake up #3
	_delay_ms(10); //must wait 160us, busy flag not available
	command(0x38); //Function set: 8-bit/2-line
	command(0x10); //Set cursor
	command(0x0c); //Display ON; Cursor ON
	command(0x6); //Entry mode set
	//command(0x20);
}
static void PORT_init(void)
{
	//PORTC_DIRSET = 0Xff;
	PORTB_DIRSET |= PIN0_bm;
	PORTB_DIRSET |= PIN1_bm;
	PORTB_DIRSET |= PIN2_bm;
	PORTE_DIRSET |= PIN0_bm;
	PORTE_DIRSET |= PIN1_bm;
	PORTE_DIRSET |= PIN2_bm;
	PORTE_DIRSET |= PIN3_bm;
	PORTF_DIRSET |= PIN2_bm;
	PORTF_DIRSET |= PIN3_bm;
	PORTF_DIRSET |= PIN4_bm;
	PORTF_DIRSET |= PIN5_bm;

}
void set_curser(uint8_t set)
{  command(0x01);
	_delay_ms(2);
	command(0x6); //Entry mode set
	_delay_ms(1);
	command(0x02); //Display ON; Cursor ON
	_delay_ms(2);
	command(set);
	_delay_ms(2);
}

void CLKCTRL_init(void)
{
	/* FREQSEL 4M */
	ccp_write_io((void*)&(CLKCTRL.OSCHFCTRLA), (CLKCTRL.OSCHFCTRLA | CLKCTRL_FREQSEL_4M_gc));
}

/* This function initializes the PORT module */

/* This function initializes the VREF module */

void DisplayRow (int row,const char *str)
{

/*
	pass pointer to 16 character string
	displays the message on line1 or line2 of LCD, depending on whether row is 1 or 2.
*/

	//unsigned char k ;

	if (row == 1)
	{
		set_curser(0x80) ;
	}
	else if(row == 2)
	{
		set_curser(0xC0) ;
	}
	else if(row == 3)
	{
		set_curser(0x94) ;
	} else
	{
		set_curser(0xD4) ;
	}

	int i;
	for(i =0;i < strlen(str);){
	write(str[i]);
	i++;}
}
void data(char c)
{
	if(c & 0x128) D7_SET; else D7_RESET;
	if(c & 0x64) D6_SET; else D6_RESET;
	if(c & 0x32) D5_SET; else D5_RESET;
	if(c & 0x16) D4_SET; else D4_RESET;
	if(c & 0x08) D3_SET; else D3_RESET;
	if(c & 0x04) D2_SET; else D2_RESET;
	if(c & 0x02) D1_SET; else D1_RESET;
	if(c & 0x01) D0_SET; else D0_RESET;

}
int main(void)
{
	 CLKCTRL_init();
	  PORT_init();
	  _delay_ms(100);
	  init();
    while(1)
    {
		_delay_ms(2000);
		DisplayRow(1,"HI");
        //TODO:: Please write your application code
    }
}

 

Madhusudan

Last Edited: Thu. Apr 22, 2021 - 01:14 PM