寄存器写的,应该用起来不错的:D
#include "stm32f10x_lib.h"
#include <stdio.h>
#include <sys.h>
#include <math.h>
#define BTin GPIOC->CRL=0xc3333333
#define BTout GPIOC->CRL=0x33333333
#define BT (GPIOC->IDR&0x80)
#define RS_1 GPIOC->BSRR=0x0100
#define RS_0 GPIOC->BRR=0x0100
#define RW_1 GPIOC->BSRR=0x0200
#define RW_0 GPIOC->BRR=0x0200
#define E_1 GPIOC->BSRR=0x0400
#define E_0 GPIOC->BRR=0x0400
#define Datain(x) GPIOC->ODR=(GPIOC->IDR&0xff00)+x
u8 busytest(void)
{
u8 a;
RS_0;
RW_1;
E_1;
BTin;
ysu(50);
a=BT;
E_0;
BTout;
return (a);
}
void Wcom(u8 com)
{
while(busytest());
ysm(1);
RS_0;
RW_0;
E_0;
ysu(5);
Datain(com);
ysu(5);
E_1;
ysu(5);
E_0;
}
void Wdata(u8 data)
{
while(busytest());
RS_1;
RW_0;
E_0;
Datain(data);
ysu(5);
E_1;
ysu(5);
E_0;
}
void adxy(u8 x,u8 y)
{
if(x==0) Wcom(0x80|y);
else Wcom(0xc0|y);
}
void putstr(u8 *str)
{
while(*str!='\0')
{
Wdata(*str);
str++;
}
}
void lcdinit(void)
{
GPIOC->CRL=0x33333333;
GPIOC->CRH&=0xfffff000;
GPIOC->CRH|=0x333;
Wcom(0x38);
ysm(5);
Wcom(0x38);
ysm(5);
Wcom(0x38);
ysm(5);
Wcom(0x0c);
ysm(5);
Wcom(0x06);
ysm(5);
Wcom(0x01);
ysm(5);
}
void putnum(s32 num) //输出整数
{
u32 lt=1;
if(num<0)
{
num=fabs(num);
Wdata('-');
}
do
{
lt*=10;
} while (num/lt);
lt/=10;
do
{
Wdata(num/lt+48);
num%=lt;
lt/=10;
}
while(lt);
}
void clear(u8 n)
{
while(n--) Wdata(' ');
}
|