|
OLED 屏幕驱动代码,亲测有效,可以显示文字,字符,字符串,图片等- #include "OLED.h"
- #include "delay.h"
- #include "CodeTable.h"
- void I2C_Configuration(void)
- {
- I2C_InitTypeDef I2C_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- /*STM32F103C8T6D¾Æ¬μÄó2¼tI2C: PB6 -- SCL; PB7 -- SDA */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;//I2C±ØDë¿a©êä3ö
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- I2C_DeInit(I2C1);//ê1óÃI2C1
- I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
- I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
- I2C_InitStructure.I2C_OwnAddress1 = 0x30;//Ö÷»úμÄI2CμØÖ·,
- I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
- I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
- I2C_InitStructure.I2C_ClockSpeed = 400000;//400K
- I2C_Cmd(I2C1, ENABLE);
- I2C_Init(I2C1, &I2C_InitStructure);
- }
- void OLED_IIC_Start(void)
- {
- OLED_IIC_SDA = 1;
- OLED_IIC_SCL = 1;
- delay_us(2);
- OLED_IIC_SDA = 0;//START:when CLK is high,DATA change form high to low
- delay_us(2);
- OLED_IIC_SCL = 0;
- void OLED_IIC_Stop(void)
- {
- OLED_IIC_SCL = 0;
- OLED_IIC_SDA = 0;//STOP:when CLK is high DATA change form low to high
- delay_us(2);
- OLED_IIC_SCL = 1;
- OLED_IIC_SDA = 1;//·¢ËíI2C×üÏß½áêøDÅoÅ
- delay_us(2);
- }
- void I2C_Write_Byte(uint8_t addr,uint8_t data)
- {
- while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
-
- I2C_GenerateSTART(I2C1, ENABLE);
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
- I2C_Send7bitAddress(I2C1, OLED_ADDRESS, I2C_Direction_Transmitter);
- while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
- I2C_SendData(I2C1, addr);/
- while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
- I2C_SendData(I2C1, data);/
- while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
-
- I2C_GenerateSTOP(I2C1, ENABLE);/
- }
复制代码
|
|