暂时放弃了,整不了,怎么编译就是不/*************HLK-W801-KIT-V1.1********************/
/*************1.3寸OLED IIC************************/
/*************ID:共同学习stm8**********************/
/*************跨平台,一切都是运算*******************/
/*******.******20240421*****************************/
//0X0000 GPIO 数据寄存器 GPIO_DATA RW 读写 GPIO 当前数据 0X180B
#define GPIOA_DATA (*(volatile unsigned int*)(0x40011200+0x0000))
//0X0004 GPIO 数据使能寄存器 GPIO_DATA_EN RW 配置 GPIO_DATA 的使能位 0XFFFF
#define GPIOA_DATA_EN (*(volatile unsigned int*)(0x40011200+0X0004))
//0X0008 GPIO 方向控制寄存器 GPIO_DIR RW 配置 GPIO 方向 0X0000
#define GPIOA_DIR (*(volatile unsigned int*)(0x40011200+0X0008))
//0X000C GPIO 上拉控制寄存器 GPIO_PULL_EN RW 配置 GPIO 上拉 0XFFFF
#define GPIOA_PULL_EN (*(volatile unsigned int*)(0x40011200+0X000c))
//0X001C GPIO 下拉控制寄存器 GPIO_DN_ENA RW 配置 GPIO 下拉 0X0000
#define GPIOA_DN_ENA (*(volatile unsigned int*)(0x40011200+0X001c))
//0X0000 GPIO 数据寄存器 GPIO_DATA RW 读写 GPIO 当前数据 0X180B
#define GPIOB_DATA (*(volatile unsigned int*)(0x40011400+0x0000))
//0X0004 GPIO 数据使能寄存器 GPIO_DATA_EN RW 配置 GPIO_DATA 的使能位 0XFFFF
#define GPIOB_DATA_EN (*(volatile unsigned int*)(0x40011400+0X0004))
//0X0008 GPIO 方向控制寄存器 GPIO_DIR RW 配置 GPIO 方向 0X0000
#define GPIOB_DIR (*(volatile unsigned int*)(0x40011400+0X0008))
//0X000C GPIO 上拉控制寄存器 GPIO_PULL_EN RW 配置 GPIO 上拉 0XFFFF
#define GPIOB_PULL_EN (*(volatile unsigned int*)(0x40011400+0X000c))
//0X001C GPIO 下拉控制寄存器 GPIO_DN_ENA RW 配置 GPIO 下拉 0X0000
#define GPIOB_DN_ENA (*(volatile unsigned int*)(0x40011400+0X001c))
/**************************************************/
// _______________________
// | 1.3' OLED IIC |
// | GND|VCC|SCL|SDA |
// | 128*64 |
// |_______________________|
//数据sda-----PA1
//时钟scl-----PA2
//sda¯¯\__X=7=X===X===X===X===X===X===X=0=X¯\_/X__/¯¯
//scl¯¯¯¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯¯\_/¯¯¯¯
//_____s____1___2___3___4___5___6___7___8__ack____p__
/**************************************************/
void iic_chushihua(); //iic初始化;
void iic_qishi(); //iic起始信号;
void iic_yingda(); //iic应答信号;
void iic_tingzhi(); //iic停止信号;
void iic_xie_byte(unsigned char iic_i1); //iic写一个字节;
void yanshi_1ms(); //延时1ms;
void yanshi_1s(); //延时1秒;
void yanshi(unsigned char y1); //延时
/**************************************************/
//#include <stdio.h>
//#include "wm_hal.h"
int main(void)
{
GPIOA_DATA_EN |=(1<<3);
GPIOA_DIR |=1<<3;
#define led_l GPIOA_DATA &=~(1<<3)
#define led_h GPIOA_DATA |=(1<<3)
GPIOB_DATA_EN |=(1<<5);
GPIOB_DIR |=(1<<5);
#define led_1_l GPIOB_DATA &=~(1<<5)
#define led_1_h GPIOB_DATA |=(1<<5)
GPIOB_DATA_EN |=(1<<25);
GPIOB_DIR |=(1<<25);
#define led_2_l GPIOB_DATA &=~(1<<25)
#define led_2_h GPIOB_DATA |=(1<<25)
/**************************************************/
led_1_h;
led_2_h;
//while(1){};
iic_chushihua(); //iic初始化;
iic_qishi();
iic_xie_byte(0x78);
void iic_yingda();
iic_tingzhi();
led_1_l;
//led_2_h;
while (1)
{
led_l;
led_1_l;
led_2_l;
yanshi_1s();
//yanshi(10);
led_h;
led_1_h;
led_2_h;
yanshi_1s();
//yanshi(10);
}
return 0;
}
/**************************************************/
void yanshi_1ms() //延时1ms;
{
volatile unsigned int x1=7500;
//while(x1 --){ __NOP(); __NOP(); __NOP(); __NOP(); __NOP();}
while(x1 --){};
}
/**************************************************/
void yanshi_1s() //延时1秒;
{
volatile unsigned char z1,z2,z3;
z1 =100; //循环次数;
do
{
do
{
z2 =100;
do{z3 =100;} while(z3--); //细调;
}
while(z2--); //粗调;
}
while(z1--);
}
/**************************************************/
void yanshi(unsigned char y1) //延时
{
while(y1--)
{/*
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP();__NOP(); __NOP(); __NOP(); __NOP(); __NOP();
*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
}
/**************************************************/
void iic_chushihua() //iic初始化;
{
//数据sda-----PA1
//时钟scl-----PA2
//#define xian_sda_l GPIOA_DIR |=(1<<1); __NOP(); __NOP(); GPIOA_DATA &=~(1<<1) /*sda输出,低;*/
//#define xian_sda_h GPIOA_DIR |=(1<<1); __NOP(); __NOP(); GPIOA_DATA |=(1<<1) /*sda输出,高;*/
//#define xian_sda_shuru GPIOA_DIR &=~(1<<1); __NOP(); __NOP(); /*sda输入,高;*/
//#define xian_sda_shuju GPIOA_DATA &=(1<<1) /*sda,io状态;*/
//#define xian_scl_l GPIOA_DIR |=(1<<2); __NOP(); __NOP(); GPIOA_DATA &=~(1<<2) /*scl输出,低;*/
//#define xian_scl_h GPIOA_DIR |=(1<<2); __NOP(); __NOP(); GPIOA_DATA |=(1<<2) /*scl输出,高;*/
//#define xian_scl_shuru GPIOA_DIR &=~(1<<2); __NOP(); __NOP(); /*输入,高;*/
//#define xian_scl_shuju GPIOA_DATA &=(1<<2) /*scl,io状态;*/
//#define sda_l GPIOA_DIR |=(1<<1); __NOP(); __NOP(); GPIOA_DATA &=~(1<<1) /*sda输出,低;*/
//#define sda_h GPIOA_DIR &=~(1<<1); __NOP(); __NOP() /*sda输入,高;*/
//#define sda_data GPIOA_DATA &(1<<1)
//#define scl_l GPIOA_DIR |=(1<<2); __NOP(); __NOP(); GPIOA_DATA &=~(1<<2) /*scl输出,低;*/
//#define scl_h GPIOA_DIR &=~(1<<2); __NOP(); __NOP(); /*输入,高;*/
//#define scl_data GPIOA_DATA &(1<<2)
#define sda_l GPIOA_DIR |=(1<<1); GPIOA_DATA &=~(1<<1) /*sda输出,低;*/
#define sda_h GPIOA_DIR &=~(1<<1); /*sda输入,高;*/
#define sda_data GPIOA_DATA &(1<<1)
#define scl_l GPIOA_DIR |=(1<<2); GPIOA_DATA &=~(1<<2) /*scl输出,低;*/
#define scl_h GPIOA_DIR &=~(1<<2); /*输入,高;*/
#define scl_data GPIOA_DATA &(1<<2)
/**************************************************/
GPIOA_DATA_EN |=1<<1; //sda数据使能;
GPIOA_DATA_EN |=1<<2; //scl时钟使能;
GPIOA_PULL_EN |=1<<1; //sda数据上拉电阻;
GPIOA_PULL_EN |=1<<2; //scl时钟上拉电阻;
yanshi(100);
}
void iic_qishi() //iic起始信号;
{
//sda¯¯\__
//scl¯¯¯¯¯
sda_h;
scl_h
yanshi(10);
sda_l;
yanshi(10);
}
void iic_xie_byte(unsigned char iic_i1) //iic写一个字节;
{
//sda¯¯\__X=7=X===X===X===X===X===X===X=0=/¯\_/X__/¯¯
//scl¯¯¯¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯\_/¯¯\_/¯¯¯¯
//_____s____1___2___3___4___5___6___7___8__ack____p__
scl_l; yanshi(10); if(iic_i1 &(1<<7)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<6)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<5)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<4)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<3)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<2)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<1)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
scl_l; yanshi(10); if(iic_i1 &(1<<0)){sda_h;} else{sda_l;} yanshi(10);scl_h; yanshi(10);
}
void iic_yingda() //iic应答信号;
{
//sda/¯\____/
//scl_/¯¯¯¯\_
scl_l;
yanshi(10);
sda_h;
yanshi(10);
scl_h;
yanshi(10);
if(~(sda_data))
{
led_1_h;
//while(1); //卡死
}
scl_l;
yanshi(10);
}
/**************************************************/
void iic_tingzhi() //iic停止信号;
{
//sdaX\__/¯
//scl\_/¯¯¯
scl_l;
yanshi(10);
sda_l;
yanshi(10);
scl_h;
yanshi(10);
sda_h;
yanshi(10);
}
/**************************************************/
/**************************************************/
/**************************************************/
按想的走,让灯亮就是不亮,想让他卡在那就是不动,也不知道进没进函数
|