Max32630(三)——OLED屏显示时间
本帖最后由 29447945 于 2017-9-13 18:57 编辑一个OLED显示屏从许久以前就开始调,到今天终于可以显示了。手里有两个屏,一个SPI通信,一个IIC通信,SPI屏在STM32 的板子上点亮之后,代码移植到MAX32630上,就是不亮;
尝试多次无果后,换了这个IIC通信,结果代码移植过来还是不亮;
首先尝试用模拟IIC,在换硬件IIC,各种无用;今天拿示波器看下波形,一看就知道是上拉电阻的问题,看原理图有,但是板子没有焊,
不知道为什么美信不把两个电阻焊上呢?
焊好电阻,看下波形,终于像样了
然后字库取模加上,可以正常显示了;
看下效果
hal_oled.c
#include "main.h"
#include "hal_oled.h"
#include "stdlib.h"
#include "oledfont.h"
#include "i2cm.h"
#define XLevelL 0x00
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 64
#define Brightness 0xCF
#define X_WIDTH 128
#define Y_WIDTH 64
#define OLED_I2CM MXC_I2CM1
const sys_cfg_i2cm_t oled_sys_cfg = {
.clk_scale = CLKMAN_SCALE_AUTO,
.io_cfg = IOMAN_I2CM1(IOMAN_MAP_A, 1)
};
const gpio_cfg_t IIC[] = {
{ PORT_3, PIN_4, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
{ PORT_3, PIN_5, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
{ PORT_3, PIN_4, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP },
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void OLED_Initial()
{
// u8 rslt;
// rslt = I2CM_Init(OLED_I2CM, &oled_sys_cfg, I2CM_SPEED_400KHZ);
GPIO_Config(&IIC);
GPIO_Config(&IIC);
delay_ms(100); //延时
Write_IIC_Command(0xAE); //display off
Write_IIC_Command(0x20); //Set Memory Addressing Mode
Write_IIC_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
Write_IIC_Command(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
Write_IIC_Command(0xc8); //Set COM Output Scan Direction
Write_IIC_Command(0x00);//---set low column address
Write_IIC_Command(0x10);//---set high column address
Write_IIC_Command(0x40);//--set start line address
Write_IIC_Command(0x81);//--set contrast control register
Write_IIC_Command(0x7f);
Write_IIC_Command(0xa1);//--set segment re-map 0 to 127
Write_IIC_Command(0xa6);//--set normal display
Write_IIC_Command(0xa8);//--set multiplex ratio(1 to 64)
Write_IIC_Command(0x3F);//
Write_IIC_Command(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
Write_IIC_Command(0xd3);//-set display offset
Write_IIC_Command(0x00);//-not offset
Write_IIC_Command(0xd5);//--set display clock divide ratio/oscillator frequency
Write_IIC_Command(0xf0);//--set divide ratio
Write_IIC_Command(0xd9);//--set pre-charge period
Write_IIC_Command(0x22); //
Write_IIC_Command(0xda);//--set com pins hardware configuration
Write_IIC_Command(0x12);
Write_IIC_Command(0xdb);//--set vcomh
Write_IIC_Command(0x20);//0x20,0.77xVcc
Write_IIC_Command(0x8d);//--set DC-DC enable
Write_IIC_Command(0x14);//
Write_IIC_Command(0xaf);//--turn on oled panel
LCD_CLS();
LCD_Set_Pos(0,0);
}
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
SCL_HIGH;
SDA_HIGH;
delay_us(2);
SDA_LOW;
delay_us(2);
SCL_LOW;
delay_us(2);
}
/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
SCL_LOW;
SDA_LOW;
delay_us(2);
SCL_HIGH;
delay_us(2);
SDA_HIGH;
delay_us(2);
}
/**********************************************
// IIC Write byte
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(IIC_Byte&0x80)//1?0?
SDA_HIGH;
else
SDA_LOW;
SCL_HIGH;
delay_us(2);
SCL_LOW;
delay_us(2);
IIC_Byte<<=1; //loop
}
SDA_HIGH;
SCL_HIGH;
delay_us(2);
SCL_LOW;
delay_us(2);
}
/**********************************************
// IIC Write Command
**********************************************/
void Write_IIC_Command(unsigned char IIC_Command)
{
// u8 cmd[] = {0x00};
// I2CM_Write(OLED_I2CM,0x78,cmd,1,&IIC_Command,1);
IIC_Start();
Write_IIC_Byte(0x78); //Slave address,SA0=0
Write_IIC_Byte(0x00); //write command
Write_IIC_Byte(IIC_Command);
IIC_Stop();
}
/**********************************************
// IIC Write Data
**********************************************/
void Write_IIC_Data(unsigned char IIC_Data)
{
// u8 cmd[] = {0x40};
// I2CM_Write(OLED_I2CM,0x78,cmd,1,&IIC_Data,1);
IIC_Start();
Write_IIC_Byte(0x78);
Write_IIC_Byte(0x40); //write data
Write_IIC_Byte(IIC_Data);
IIC_Stop();
}
/*********************LCD 设置坐标************************************/
void LCD_Set_Pos(unsigned char x, unsigned char y)
{
Write_IIC_Command(0xb0+y);
Write_IIC_Command(((x&0xf0)>>4)|0x10);
Write_IIC_Command((x&0x0f)|0x01);
}
/*********************LCD复位************************************/
void LCD_CLS(void)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
Write_IIC_Command(0xb0+y);
Write_IIC_Command(0x01);
Write_IIC_Command(0x10);
for(x=0;x<X_WIDTH;x++)
Write_IIC_Data(0);
}
}
/***************功能描述:显示6*8一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void LCD_P6x8Str(unsigned char x,unsigned chary,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch!='\0')
{
c =ch-32;
if(x>126){x=0;y++;}
LCD_Set_Pos(x,y);
for(i=0;i<6;i++)
Write_IIC_Data(F6X8);
x+=6;
j++;
}
}
/*******************功能描述:显示8*16一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void LCD_P8x16Str(unsigned char x,unsigned chary,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch!='\0')
{
c =ch-32;
if(x>120){x=0;y++;}
LCD_Set_Pos(x,y);
for(i=0;i<8;i++)
Write_IIC_Data(F8X16);
LCD_Set_Pos(x,y+1);
for(i=0;i<8;i++)
Write_IIC_Data(F8X16);
x+=8;
j++;
}
}
/*****************功能描述:显示16*16点阵显示的坐标(x,y),y为页范围0~7****************************/
void LCD_P16x16Ch(unsigned char x,unsigned chary,unsigned charN)
{
// unsigned char wm=0;
// unsigned int adder=32*N;//
// LCD_Set_Pos(x , y);
// for(wm = 0;wm < 16;wm++)//
// {
// Write_IIC_Data(F16x16);
// adder += 1;
// }
// LCD_Set_Pos(x,y + 1);
// for(wm = 0;wm < 16;wm++) //
// {
// Write_IIC_Data(F16x16);
// adder += 1;
// }
}
/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
void Draw_BMP(unsigned char x0,unsigned chary0,unsigned char x1,unsigned chary1,unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y;
if(y1%8==0) y=y1/8;
else y=y1/8+1;
for(y=y0;y<y1;y++)
{
LCD_Set_Pos(x0,y);
for(x=x0;x<x1;x++)
{
Write_IIC_Data(BMP);
}
}
}
void LCD_ShowNum(u8 x,u8 y,u32 Num,u8 Size)
{
u8 Len,Temp;
u8 i;
Len = 0;
while(Num % 10)
{
Temp = Num %10 + 0x10;
Num /= 10;
}
for(i = 0; i < Len; i ++)
{
switch(Size)
{
case 1:
LCD_P6x8Str(x + i * 6,y,&Temp);
break;
case 2:
LCD_P8x16Str(x + i * 8,y,&Temp);
break;
default:
break;
}
}
}
hal_oled.h
#ifndef _hal_oled_h
#define _hal_oled_h
#include "gpio_config.h"
#include "stdint.h"
#include "def.h"
extern const gpio_cfg_t IIC[];
/*************Pin Define***************/
#define SCL_HIGHGPIO_OutSet((&IIC)) //LED1点亮//P1OUT|=BIT0 //SCL P1.0
#define SCL_LOW GPIO_OutClr(&IIC) //P1OUT&=~BIT0
#define SDA_HIGHGPIO_OutSet((&IIC)) //P1OUT|=BIT1 //SDA P1.1
#define SDA_LOW GPIO_OutClr(&IIC) //P1OUT&=~BIT1
/****************************************************/
void OLED_Initial(void);
void IIC_Start(void);
void IIC_Stop(void);
void Write_IIC_Command(unsigned char IIC_Command);
void Write_IIC_Data(unsigned char IIC_Data);
void Write_IIC_Byte(unsigned char IIC_Byte);
void LCD_Set_Pos(unsigned char x, unsigned char y);
void LCD_CLS(void);
void LCD_P8x16Str(unsigned char x,unsigned chary,unsigned char ch[]);
void LCD_P16x16Ch(unsigned char x,unsigned chary,unsigned charN);
void LCD_P6x8Str(unsigned char x,unsigned chary,unsigned char ch[]);
void Draw_BMP(unsigned char x0,unsigned chary0,unsigned char x1,unsigned chary1,unsigned char BMP[]);
void LCD_ShowNum(u8 x,u8 y,u32 Num,u8 Size);
#endif
显示
void OLED_Task(void)
{
static u32 PointM = 0;
static u8 mState = 0;
char Data = "hh:mm:ss";
if( ( OsDelayCCnt - PointM ) >= T_1S)
{
PointM = OsDelayCCnt;
LCD_CLS();
LCD_P8x16Str(0,0,"MAX32630");
LCD_P8x16Str(0,2,"EEWORLD");
LCD_P8x16Str(0,4,"Smart Watch");
// LCD_P6x8Str(34,6,"2014-11-22");
sprintf(Data,"%02d:%02d:%02d",User.RtcTime.Hour,User.RtcTime.Min,User.RtcTime.Sec);
LCD_P8x16Str(0,6,Data);
}
}
<p>MAX32630/MAX32631具有Arm® Cortex®-M4 FPU CPU,具有超低功耗、高效信号处理功能,</p>
<p>灵活的电源模式、智能外设管理单元(PMU)、动态时钟门控和固件控制功率门控最大程度降低特定应用的功耗。</p>
<p>提供多个SPI、UART、I2C、1-Wire®主机接口和USB接口。带可选参考的四输入、10位ADC能够监测外部传感器。</p>
页:
[1]