大大您好 小弟又上來麻煩伱了 不好意思
這是APP023_3的GLCD測試程式
小弟只改了p30fxxxx.h-->p30F6010a.h
想說先看看這程式能run起來在修,可是好像不行,想請大大們給一下指導好嗎?
附檔是rum的結果與設定
請您幫忙一下 謝謝!
#include <p30F6010a.h>
#include "GLCD_30IO_APP023.h"
#define CPU_FCY 16
#define LCD_RS LATBbits.LATB10 // RS = 1 >> Data , =0 >> Command
#define LCD_RW LATBbits.LATB11 // RW = 0 >> Write , = 1 >> Read
#define LCD_E LATGbits.LATG9
#define DIR_LCD_RS TRISBbits.TRISB10
#define DIR_LCD_RW TRISBbits.TRISB11
#define DIR_LCD_E TRISGbits.TRISG9
unsigned char LCD_StatusByte ;
int LCDIsBusy(void)
{
int BusyLoop ;
for (BusyLoop = 0 ; BusyLoop < 30 ; BusyLoop++) ;
LCD_StatusByte = cmdreadLCD() ;
for (BusyLoop = 0 ; BusyLoop < 30 ; BusyLoop++) ;
return ((LCD_StatusByte >> 7) & 0x0001) ;
}
void LCD_Initial(void)
{
TRISD &= 0b1111011110000000 ;
LCD_E = 0 ;
DIR_LCD_RS = 0 ;
DIR_LCD_RW = 0 ;
DIR_LCD_E = 0 ;
LCD_E_Delay() ;
cmdwriteLCD(0x00) ;
LCD_Delay200usX(40) ;
cmdwriteLCD(0x30) ;
LCD_Delay200usX(25); // Wait for > 4.1 ms --> 200us * 25 = 5 ms
cmdwriteLCD(0x30) ;
LCD_Delay200usX(20) ;
cmdwriteLCD(0x30) ;
LCD_Delay200usX(10) ;
cmdwriteLCD(0x08) ;
LCD_Delay200usX(10) ;
cmdwriteLCD(0x01) ;
LCD_Delay200usX(50) ; // Display OFF
cmdwriteLCD(0x06) ;
LCD_Delay200usX(10) ; // Clear Display = 1.5 ms
cmdwriteLCD(0x30) ;
LCD_Delay200usX(10) ;
cmdwriteLCD(0x08) ; // Display ON
LCD_Delay200usX(10) ;
cmdwriteLCD(0x0e) ;
LCD_Delay200usX(10) ;
cmdwriteLCD(0x06) ; // Display ON
LCD_Delay200usX(50) ;
}
void setcurLCD( char Cur_X , char Cur_Y )
{
unsigned char BaseAddr ;
switch ( Cur_Y )
{
case 0 :
BaseAddr = 0x80 ;
break ;
case 1 :
BaseAddr = 0x90 ;
break ;
case 2 :
BaseAddr = 0x88 ;
break ;
case 3 :
BaseAddr = 0x98 ;
break ;
default :
BaseAddr = 0x80 ;
break ;
}
BaseAddr += Cur_X ;
while ( LCDIsBusy()) ;
cmdwriteLCD(BaseAddr) ;
}
void putcLCD( unsigned char TheChar)
{
datawriteLCD((unsigned int)TheChar);
}
void putsLCD( unsigned char *OutString )
{
while ( *OutString != 0x00 )
{
while ( LCDIsBusy() );
putcLCD( *OutString++ ) ;
}
}
void putrsLCD( const unsigned char *OutString )
{
while ( *OutString != 0x00 )
{
while ( LCDIsBusy() );
putcLCD( *OutString++ ) ;
}
}
void LCD_Delay200usX(int UnitOf200us)
{
int Loop_200usX ;
for ( Loop_200usX = 0 ; Loop_200usX < UnitOf200us ; Loop_200usX ++ )
LCD_Delay200us( ) ;
}
void LCD_Delay200us(void)
{
int Loop_200us ;
for ( Loop_200us = 0 ; Loop_200us < CPU_FCY * 40 ; Loop_200us++) ;
}
// LCD Data @ RD0 .. RD6 and RD10
unsigned char datareadLCD(void) // Read data from LCD
{
int Temp_PORTD ;
int Return_Data ;
TRISD |= 0b0000100001111111 ; // Make all LCD data pins as INPUT
LCD_RS = 1 ;
LCD_RW = 1 ;
LCD_E_Delay() ;
LCD_E = 1 ;
LCD_E_Delay() ;
Temp_PORTD = PORTD ;
LCD_E = 0 ;
TRISD &= 0b1111011110000000 ;
Return_Data = Temp_PORTD ;
if ( Temp_PORTD & 0b0000100000000000 ) Return_Data |= 0b10000000 ;
else Return_Data &= 0b01111111 ;
return (unsigned char)Return_Data ;
}
unsigned char cmdreadLCD(void) // Read data from LCD
{
int Temp_PORTD ;
int Return_Data ;
TRISD |= 0b0000100001111111 ; // Make all LCD data pins as INPUT
LCD_RS = 0 ;
LCD_RW = 1 ;
LCD_E_Delay() ;
LCD_E = 1 ;
LCD_E_Delay() ;
Temp_PORTD = PORTD ;
LCD_E = 0 ;
TRISD &= 0b1111011110000000 ;
Return_Data = Temp_PORTD ;
if ( Temp_PORTD & 0b0000100000000000 ) Return_Data |= 0b10000000 ;
else Return_Data &= 0b01111111 ;
return (unsigned char)Return_Data ;
}
void datawriteLCD(unsigned char wdata) // Write data to LCD
{
LATD &= 0b1111011110000000 ;
if ( wdata & 0b0000000010000000 )
LATD |= 0b0000100000000000 ;
wdata &= 0b01111111 ;
LATD |= wdata ;
LCD_RS = 1 ;
LCD_RW = 0 ;
LCD_E_Delay() ;
LCD_E = 1 ;
LCD_E_Delay() ;
LCD_E = 0 ;
LCD_E_Delay() ;
}
void cmdwriteLCD(unsigned char wdata) // Write Command to LCD
{
LATD &= 0b1111011110000000 ;
if ( wdata & 0b0000000010000000 )
LATD |= 0b0000100000000000 ;
wdata &= 0b01111111 ;
LATD |= wdata ;
LCD_RS = 0 ;
LCD_RW = 0 ;
LCD_E_Delay() ;
LCD_E = 1 ;
LCD_E_Delay() ;
LCD_E = 0 ;
LCD_E_Delay() ;
}
void LCD_E_Delay(void)
{
int E_Loop ;
for ( E_Loop = 0 ; E_Loop < CPU_FCY * 5 ; E_Loop ++ ) ;
}