OLED显示部分调试
This commit is contained in:
28
Src/config.h
Normal file
28
Src/config.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
//#define NDEBUG //取消断言
|
||||
#include <assert.h> // 断言库
|
||||
|
||||
#include <intrins.h>
|
||||
|
||||
#include <STC15.H>
|
||||
|
||||
|
||||
#define FOSC 30000000UL // 定义系统频率
|
||||
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint8_t u8;
|
||||
|
||||
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
sbit SDA = P2^7;
|
||||
sbit SCL = P2^6;
|
||||
|
||||
|
||||
#endif
|
76
Src/main.c
Normal file
76
Src/main.c
Normal file
@ -0,0 +1,76 @@
|
||||
//System
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <STC15.H>
|
||||
// Driver
|
||||
#include "uart.h"
|
||||
#include "iic.h"
|
||||
// Config
|
||||
#include "config.h"
|
||||
// Lib
|
||||
#include "delay.h"
|
||||
#include "oled12864_drv.h"
|
||||
|
||||
void SystemClock_Init(void) {
|
||||
// 烧录时选择30M主频
|
||||
CLK_DIV = 0x00; // 时钟不分频(30MHz直接输出)
|
||||
}
|
||||
|
||||
void main() {
|
||||
u8 addr;
|
||||
|
||||
SystemClock_Init(); // 时钟配置
|
||||
|
||||
EA = 1; // 开总中断
|
||||
|
||||
Delay_Init();
|
||||
Uart1_Init();
|
||||
|
||||
printf("IIC_Init()\r\n");
|
||||
IIC_Init();
|
||||
|
||||
printf("OLED_Init()\r\n");
|
||||
OLED_Init();
|
||||
|
||||
DelayMs(100); // 初始化延时
|
||||
|
||||
printf("OLED_ShowPrintf()\r\n");
|
||||
OLED_ShowPrintf(0, 0, "Hello, oWorld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL, OLED_SHOW);
|
||||
|
||||
OLED_ShowPrintf(0, 2, "Hello, 2World!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL, OLED_CLS);
|
||||
|
||||
OLED_ShowPrintf(0, 1, "Hello, 1Worl2d!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL, OLED_CLS);
|
||||
|
||||
OLED_ShowPrintf(0, 4, "Hello, 4Wo4rld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL, OLED_CLS);
|
||||
|
||||
OLED_ShowNum(4, 6, 123456789, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL, OLED_SHOW);
|
||||
|
||||
while(1) {
|
||||
printf("Scanning I2C bus...\r\n");
|
||||
|
||||
for(addr = 0x08; addr <= 0x78; addr++) { // 有效地址范围
|
||||
IIC_Start();
|
||||
IIC_SendByte(addr << 1); // 发送写命令
|
||||
if(IIC_WaitAck()) {
|
||||
printf("Device found at: 0x%02X\n", addr);
|
||||
}
|
||||
IIC_Stop();
|
||||
DelayMs(1);
|
||||
}
|
||||
|
||||
printf("Scan complete.\n");
|
||||
DelayMs(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void Uart1_Isr(void) interrupt 4
|
||||
{
|
||||
if (TI) //检测串口1发送中断
|
||||
{
|
||||
TI = 0; //清除串口1发送中断请求位
|
||||
}
|
||||
if (RI) //检测串口1接收中断
|
||||
{
|
||||
RI = 0; //清除串口1接收中断请求位
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user