#include "reg52.h"
#include <stdio.h>
#include <oled.h>
sbit SDA = P2 ^ 1;
sbit SCL = P2 ^ 0;
char recive=0;
unsigned char a;
//========================================================
//串口通信初始化
void UartInit(void) //9600bps@11.0592MHz
{
SCON = 0x50;
TMOD &= 0x0F;
TMOD |= 0x20;
TL1 = 0xFD;
TH1 = 0xFD;
ET1 = 0;
TR1 = 1;
ES = 1;
EA = 1;
}
//========================================================
void SendByte (unsigned char dat) //发送一个字符
{
SBUF = dat;
while(!TI);
TI = 0;
}
//===========================================================
char putchar(char c) //获取一个字符
{
SendByte(c);
return c;
}
//==============================================================
//延迟函2,ms=1,延迟1ms
void delay(unsigned int ms)
{
unsigned char j = 0;
while (ms--)
for (j = 0; j < 254; j++);
}
//==============================================================
//OLED显示函数
void OLED_display()
{
OLED_Init(); //初始化OLED
OLED_Clear(); //OLED清屏
OLED_ShowChar(5,5,'A',8);
OLED_ShowString(1,2,"Hello World",8);
}
//=================================================================
void UART() interrupt 4
{
if(RI == 1)
{
a = SBUF;
recive=2;
switch(recive)
{
case 0:printf("停止\r\n");break;
case 1:printf("3\r\n");break;
case 2:printf("2\r\n");break;
case 3:printf("1\r\n");break;
default: break;
}
RI=0;
}
}
//====================================================================
//主程序
void main()
{
UartInit();
//printf("Start now!\r\n");
OLED_display();
while(1)
{
}
}
//=================================================================
|