#include "p30F4011.h"
_FOSC(CSW_FSCM_OFF & XT_PLL8); //Run this project using an external crystal
//routed via the PLL in 8x multiplier mode
//For the 7.3728 MHz crystal we will derive a
//throughput of 7.3728e+6*8/4 = 14.7 MIPS(Fcy)
//,~68 nanoseconds instruction cycle time(Tcy).
_FWDT(WDT_OFF); //Turn off the Watch-Dog Timer.
_FBORPOR(MCLR_EN & PWRT_OFF & PWMxL_ACT_HI);
//Enable MCLR reset pin and turn off the power-up timers.
_FGS(CODE_PROT_OFF); //Disable Code Protection
//**********************************************************************
#define SPK PORTFbits.RF6
//LCD 接口定义
#define set_CLK LATB |= 0x0020 //RB5=SCLK
#define clr_CLK LATB &= 0xffdf
#define set_STD LATB |= 0x0010 //RB4=STD
#define clr_STD LATB &= 0xffef
#define set_CS LATB |= 0x0008 //RB3=CS
#define clr_CS LATB &= 0xfff7
//
const unsigned char HZ[]="苏州大学机电学院";
const unsigned char TAB[]={0xe7,0x60,0xcb,0xe9,0x6c,0xad,0xaf,0xe0,0xef,0xed};
unsigned char adrline,adrcolumn;
//---------------------------------------------------------------------
int dx,dy,dw;
//---------------------------------------------------------------------
void Init(void); // Initializes dsPIC and peripherals
void Delay(unsigned int count);
void Dpout(char cnt);
void DpInit(void);
unsigned char Key_read(void);
void Wr_lcd(char sel,char dat);
//---------------------------------------------------------------------
//**********************************************************************
main ( void )
{
unsigned int ptr,j;
unsigned char buf0,buf1,buf2,buf;
Init();
Wr_lcd(0,0x30);Delay(500); //LCD init
Wr_lcd(0,0x01);Delay(500); //Clr Screen
for(j=0;j<100;j++) Delay(50000);
Wr_lcd(0,0x30);Delay(500); //LCD init
Wr_lcd(0,0x01);Delay(500); //Clr Screen
Wr_lcd(0,0x06);Delay(500);
Wr_lcd(0,0x0c);Delay(500); //光标显示设置
Wr_lcd(0,0x80); //显示开机信息
for(j=0;j<16;j++) Wr_lcd(1,HZ[j]);
while(1)
{
DpInit();
}
} // end main
//**********************************************************
//---------------------------------------------------------------------
void Init(void)
{ //PORTB = 0xffff; // Port RB0-RB5=Speed input:D0-D5
PORTC = 0x0000; //
PORTD = 0x000f; // Port RD0-RD3 = K1-K4
PORTE = 0x0100;
PORTF = 0x00ff;
TRISB = 0xffc7; // RB0 for A/D input
TRISC = 0x00ff;
TRISD = 0x0000; // PortD for 4094
TRISE = 0x0100; // RE8 for HC165 input
TRISF = 0x0000;
//
}
//---------------------------------------------------------------------
void Wr_lcd(char sel,char dat)
{
char i;
set_CS;Delay(10); //CS=1
clr_CLK;Delay(10); //CLK=0
set_STD;Delay(10); //STD=1
for(i=0;i<5;i++) //发送5个"1"
{ set_CLK;Delay(10);
clr_CLK;Delay(10);
}
clr_STD;Delay(10);
set_CLK;Delay(10); //发送RW="0"
clr_CLK;Delay(10);
if(sel==0) clr_STD; //发送RS
else set_STD;
Delay(10);
set_CLK;Delay(10);
clr_CLK;Delay(10);
clr_STD;Delay(10);
set_CLK;Delay(10); //发送"0"
clr_CLK;Delay(10);
for(i=0;i<4;i++) //写高4位数据
{ if(dat&0x80>>i) set_STD;
else clr_STD;
Delay(10);
set_CLK;Delay(10);
clr_CLK;Delay(10);
}
clr_STD;Delay(10);
for(i=0;i<4;i++) //写4位"0"
{ set_CLK;Delay(10);
clr_CLK;Delay(10);
}
for(i=4;i<8;i++) //写低4位数据
{ if(dat&0x80>>i) set_STD;
else clr_STD;
Delay(10);
set_CLK;Delay(10);
clr_CLK;Delay(10);
}
clr_STD;Delay(10);
for(i=0;i<4;i++) //写4位"0"
{ set_CLK;Delay(10);
clr_CLK;Delay(10);
}
clr_CS;Delay(10); //CS=0
}
//--------------------------------------------
//
void DpInit(void)
{ unsigned char j;
Wr_lcd(0,0x30);Delay(500); //LCD init
Wr_lcd(0,0x01);Delay(500); //Clr Screen
Wr_lcd(0,0x06);Delay(500);
Wr_lcd(0,0x0f);Delay(500);
Wr_lcd(0,0x80);
for(j=0;j<64;j++) Wr_lcd(1,0x20);
Wr_lcd(0,0x80);
for(j=0;j<16;j++) Wr_lcd(1,HZ[j]);
// Wr_lcd(0,0x90);
}
//---------------------------------------------------------------------
// 读键盘数据
unsigned char Key_read(void)
{ unsigned char j,x = 0;
PLOAD = 0;
PLOAD = 1;
for(j=0;j<8;j++)
{
SCLK = 0;
x <<= 1;
if(DIN) x++;
SCLK = 1;
}
return x;
}
//---------------------------------------------------------------------
void Delay(unsigned int count) // This is a generic delay routine
{ unsigned int j;
for(j=0;j<count;j++);
}
//---------------------------------------------------------------------
// End of file.
|