我自己调出来了,发出来。
#include "C8051F330.h"
#define uint unsigned int
#define uchar unsigned char
sbit cs=P0^7;
sbit E=P0^6;
sbit RS=P0^4;
sbit RW=P0^5;
uchar tab[2][16]={ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
};
void Init_Device(void);
void delay(void)
{
uchar k;
for(k=100;k>0;k--);
}
void wcr(uchar k)
{
E=0;
RW=0;
RS=0;
E=1;
P1=k;
E=0;
delay();
}
void wcddr(uchar n)
{
E=0;
RW=0;
RS=1;
E=1;
P1=n;
E=0;
delay();
}
void clear()
{
uchar page,i;
wcr(0x3f);
wcr(0xc0);
for(page=0xb8;page<0xc0;page++)
{
wcr(page);
wcr(0x40);
for(i=0;i<64;i++)
{
wcddr(0x00);
}
}
}
void main()
{
uchar i,j;
Init_Device();
cs=1;
clear();
cs=0;
clear();
for(i=0;i<2;i++)
{
wcr(0xb8+i);
wcr(0x40);
for(j=0;j<16;j++)
wcddr(tab[i][j]);
}
while(1);
}
void PCA_Init()
{
PCA0MD &= ~0x40;
PCA0MD = 0x00;
}
void Port_IO_Init()
{
P0MDIN = 0xF3;
P0MDOUT = 0xF0;
P0SKIP = 0x0C;
XBR1 = 0x40;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
PCA_Init();
Port_IO_Init();
Oscillator_Init();
} |