I have a 16x2 lcd connected to the MG82F6D17 mcu with breadboard wires. The mcu has 0.1nf bypass cap. Here is my code
delay function was provided by megawin themselves.
The lcd just displays garbage text like " wg" and next line has "V". Port 1 on this mcu only has 5 pins -> P1.0,P1.1,P1.5,P1.6,P1.7, and i have my lcd connected (DB,4DB5,DB6,DB7) to (P1.1,P1.5,P1.6,P1.7). using P1.0~P1.6 shows nothing. Where exactly could the problem be?
Code:
#include ".\include\REG_MG82F6D17.H"
#include ".\include\Type.h"
#include ".\include\API_Macro_MG82F6D17.H"
#include ".\include\API_Uart_BRGRL_MG82F6D17.H"
#include <Intrins.h>
sfr LCD_Port=0x90; /* P1 port as data port */
#define rs P33 /* Register select pin */
#define en P34 /* Enable pin */
#define MCU_SYSCLK 12000000
#define MCU_CPUCLK (MCU_SYSCLK)
void DelayXus(u8 xUs)
{
while(xUs!=0)
{
#if (MCU_CPUCLK>=11059200)
_nop_();
#endif
#if (MCU_CPUCLK>=14745600)
_nop_();
_nop_();
_nop_();
_nop_();
#endif
#if (MCU_CPUCLK>=16000000)
_nop_();
#endif
#if (MCU_CPUCLK>=22118400)
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
#endif
#if (MCU_CPUCLK>=24000000)
_nop_();
_nop_();
#endif
#if (MCU_CPUCLK>=29491200)
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
#endif
#if (MCU_CPUCLK>=32000000)
_nop_();
_nop_();
#endif
xUs--;
}
}
/*************************************************
Function: void DelayXms(u16 xMs)
Description: dealy£¬unit:ms
Input: u16 xMs -> *1ms (1~65535)
Output:
*************************************************/
void DelayXms(u16 xMs)
{
while(xMs!=0)
{
CLRWDT();
DelayXus(200);
DelayXus(200);
DelayXus(200);
DelayXus(200);
DelayXus(200);
xMs--;
}
}
void LCD_Command (char cmnd) /* LCD16x2 command funtion */
{
LCD_Port =cmnd;
rs=0; /* Command reg. */
en=1;
DelayXus(100);
en=0;
DelayXus(1000);
}
void LCD_Char (char char_data) /* LCD data write function */
{
LCD_Port = char_data;
rs=1; /*Data reg.*/
en=1;
DelayXus(100);
en=0;
DelayXus(1000);
}
void LCD_String (char *str) /* Send string to LCD function */
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}
void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD function */
{
if (row == 0)
LCD_Command((pos & 0x0F)|0x80);
else if (row == 1)
LCD_Command((pos & 0x0F)|0xC0);
LCD_String(str); /* Call LCD string function */
}
void LCD_Init (void) /* LCD Initialize function */
{
DelayXms(100); /* LCD Power ON Initialization time >15ms */
LCD_Command (0x02); /* 4bit mode */
LCD_Command (0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_Command (0x0F); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}
void main()
{
led = 0;
PORT_SetP1PushPull(BIT0|BIT1|BIT5|BIT6|BIT7);
PORT_SetP3PushPull(BIT3|BIT4);
LCD_Init();
LCD_String("Garbage");
LCD_Command(0xC0); /* Go to 2nd line*/
/*LCD_String_xy(1,0,"Hello World"); /*write string on 2nd line*/
while(1);
}
The lcd just displays garbage text like " wg" and next line has "V". Port 1 on this mcu only has 5 pins -> P1.0,P1.1,P1.5,P1.6,P1.7, and i have my lcd connected (DB,4DB5,DB6,DB7) to (P1.1,P1.5,P1.6,P1.7). using P1.0~P1.6 shows nothing. Where exactly could the problem be?


