#include "STC12C5A60AD.H"
#include
#define uchar unsigned char
#define uint unsigned int
#define S2RI =0x01;
#define S2TI =0x02;
sbit buzzer = P3^7;
bit RX2_busy;
bit TX2_busy;
uchar Rxbuff2;
uchar a;
void PortInit(void)
{
P1M1 = 0x07;
P1M0 = 0x30;
P1M0 =0x20;
P3M1 = 0x00;
P3M0 = 0x84;
P4M1 = 0x00;
P4M0 = 0x08;
}
void UART_init(void)
{
SCON = 0x50; //8-bit variable UART
TMOD |= 0x20; //Set Timer1 as 8-bit auto reload mode
TH1 = TL1 =-3;// -(FOSC/12/32/BAUD); //Set auto-reload vaule
TR1 = 1; //Timer1 start run
ES = 1; //Enable UART interrupt
EA = 1; //Open master interrupt switch
}
void SendData2(uchar dat)
{
while(TX2_busy);
TX2_busy=1;
//S2BUF = dat;
SBUF = dat;
}
void SendString2(char *s)
{
while (*s)
{
SendData2(*s++);
}
}
void DelayUS(unsigned int Time)
{
unsigned char i;
while(Time--)
{
for(i=0;i<20;i++);
}
}
void Uart_Isr() interrupt 4 using 1
{
if (RI)
{
RI = 0; //Clear receive interrupt flag
Rxbuff2=SBUF;
RX2_busy=0;
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag
TX2_busy = 0; //Clear transmit busy flag
}
}
voidxWriteCH376Cmd(uchar Cmd)
{
SendData2(0x57);
DelayUS(1000);
SendData2(0xAB);
DelayUS(1000);
SendData2(Cmd);
}
voidxWriteCH376Data(uchar mData)
{
SendData2(mData);
}
void ce_shi_ming_ling(void)
{
xWriteCH376Cmd(0x06);
xWriteCH376Data(0x55);
}
void U_pan_mo_shi(void)
{
xWriteCH376Cmd(0x15); ///////????U?ì?£ê?
xWriteCH376Data(0x06);
}
void U_pan_lian_jie(void)
{
xWriteCH376Cmd(0x30);
}
void U_pan_chu_shi(void)
{
xWriteCH376Cmd(0x31);
}
void set_file_name(void)
{
xWriteCH376Cmd(0x2F);
xWriteCH376Cmd(0x2F);
SendString2("CDE.TXT");
xWriteCH376Cmd(0x34);
DelayUS(1000);
Rxbuff2=0;
xWriteCH376Cmd(0x22);
}
void main()
{
UART_init();
PortInit();
buzzer=0;
while(1)
{
ce_shi_ming_ling();
U_pan_mo_shi();
U_pan_lian_jie();
U_pan_chu_shi();
set_file_name();
}
}
这是我的程序 测试返回值正常 但是无法在U盘中建立文件