硬件设计的时候大意,八位数据并行传输的引脚不是连续的,所以定义了函数,一位位的传输!
#include"p33FJ128MC804.h"
_FBS(BWRP_WRPROTECT_OFF & BSS_NO_FLASH & RBS_NO_RAM);
_FSS(SWRP_WRPROTECT_OFF & SSS_NO_FLASH & RSS_NO_RAM);
_FGS(GCP_OFF & GWRP_OFF & GSS_OFF);
_FOSCSEL(FNOSC_PRIPLL & IESO_ON);
_FOSC(POSCMD_XT& OSCIOFNC_OFF & IOL1WAY_OFF & FCKSM_CSECMD);
_FWDT(WDTPOST_PS32768 & WDTPRE_PR128 & WINDIS_OFF & FWDTEN_OFF);
_FPOR(FPWRT_PWR128 & ALTI2C_OFF & LPOL_OFF & HPOL_OFF & PWMPIN_ON);
_FICD( ICS_PGD3 & JTAGEN_OFF);
#define EN PORTBbits.RB13
#define RW PORTAbits.RA10
#define RS PORTAbits.RA7
#define RST PORTBbits.RB8
#define D0 PORTBbits.RB12
#define D1 PORTBbits.RB11
#define D2 PORTBbits.RB10
#define D3 PORTCbits.RC9
#define D4 PORTCbits.RC8
#define D5 PORTCbits.RC7
#define D6 PORTCbits.RC6
#define D7 PORTBbits.RB9
#define uchar unsigned char
#define uint unsigned int
uchar menu1[]={"欢迎使用"};
void LCD_DATA(uchar d);
void LCDInit(void);
void Write_order(uchar order);
void Write_data(uchar data);
void delay(uint k);
void delay1(uint m);
void configio(void);
void System_Colck(void);
void InitXintf(void);
void display(void);
void LCD_DATA(uchar d)
{
D0=d&0x01;
D1=d&0x02;
D2=d&0x04;
D3=d&0x08;
D4=d&0x10;
D5=d&0x20;
D6=d&0x40;
D7=d&0x80;
}
void LCDInit(void)
{
RST=0;
delay(1000);
RST=1;
Write_order(0x30);
delay1(1500);//125us
Write_order(0x30);
delay1(600);//50us
Write_order(0x0c);
delay1(1500);//125us
Write_order(0x01);
delay(200);//16ms
Write_order(0x02);
delay1(1500);//125us
}
void Write_order(uchar order)
{
RS=0;
RW=0;
delay1(100);
EN=1;
delay1(100);
LCD_DATA(order);
delay1(1000);
EN=0;
delay1(100);
}
void Write_data(uchar data)
{
RS=1;
RW=0;
delay1(100);
EN=1;
delay1(100);
LCD_DATA(data);
delay1(1000);
EN=0;
delay1(100);
}
void delay(uint k)
{
uint i,j;
for(i=0; i<k;i++)
{
for(j=0;j<1000;j++)
{
}
}
}
void delay1(uint m)
{
uint i;
for(i=0; i<m;i++)
{
}
}
void System_Colck(void)
{
//Fosc = 80MHz 40MIPS
CLKDIVbits.PLLPRE = 0; //N1 = 2 7.3728MHz/2= 3.6864MHz
PLLFBDbits.PLLDIV = 38; //M = 40 3.6864*43 = 158.5152MHz
CLKDIVbits.PLLPOST = 0; //N2 = 2 158.5152/2 = 79.2576MHz
}
void configio(void)
{
TRISAbits.TRISA0 = 0;//RA0设置输出口
TRISAbits.TRISA1 = 0;//RA1设置输出口
TRISAbits.TRISA7 = 0;//RA7设置输出口
TRISAbits.TRISA10 = 0;//RA10设置输出口
TRISB = 0x0000;//B设置输出口
TRISC = 0x0000;//C设置输出口
}
void display(void)
{
uchar i;
Write_order(0x80);
for(i=0;i<9;i++)
{
Write_data(menu1[i]);
delay(100);
}
}
void main(void)
{
System_Colck();
configio();
delay(1);
LCDInit();
delay(3);
display();
while(1);
}
|