自己写的,不知道是否合你意,有详细的注释
//
#define ALLOCATE_EXTERN
#include "HC89F0541.h"
#include "OLED.h"
unsigned short u161;
unsigned char u81,u82,u83;
void main(void)
{
// Declare your local variables here
CLKSWR = 0x51; //选择内部高频RC为系统时钟,内部高频RC 2分频,Fosc=16MHz
CLKDIV = 0x02; //CPU时钟Fcpu = Fosc/分频值,比如CLKDIV=0x02,则CPU=8M
OLED_Init(); //初始化
OLED_Clear(); //清屏
OLED_GotoXY(11,1); //定位,列/行
OLED_ShowString("HC89F0541 > SH1106"); //显示字符串
OLED_GotoXY(11,5);
OLED_ShowString("21IC.COM PANXIAOYI");
while(1)
{
WDTC |= 0x10; //看门狗默认开启,程序必须定时清零看门狗
if(u83<32 || u83>126) u83=32;
OLED_GotoXY(52,3);
OLED_ShowU16(u161); //显示变量(5位数)
OLED_GotoXY(65,7);
OLED_ShowCode(u83);
u161++;
u81++;
if(u81==200)
{
u82++;
u81=0;
if(u82==5)
{
u82=0;
u83++;
}
}
}
return;
}
|