- 打卡等级:偶尔看看II
- 打卡总天数:27
- 最近打卡:2025-09-02 20:41:47
高级会员
- 积分
- 938
|
刚刚焊了一块Ai8051U最小系统板,
昨天买的5片芯片今天上午到货,
测试了一下USB下载功能.
先按下P3.2,再插上USB数据线,
串口就识别出来了.
春节买的5块芯片可以识别,
固件没有USB下载功能,
系统提示可以用USB LINK1D 下载
晚上想测试一下IIC 0.96OLED
把原来的uchar 类型改成了 u8
编译Write_IIC_Command(0XB4+y); //纵向页 这句话是产生以下警告
main.c(174): warning C188: 'parameter 1': value truncated
函数原型是这样的 ,变量IIC_Command已经定义为U8了
/*************IIC Write Command*****************/
void Write_IIC_Command(u8 IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78); //Slave address,SA0=0
Write_IIC_Byte(0x00); //write command
Write_IIC_Byte(IIC_Command);
IIC_Stop();
}
整个程序如下
#include "../../comm/AI8051U.h"
#include "stdio.h"
#include "intrins.h"
#define high 1
#define low 0
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
sbit OLED_SCL=P1^1; //
sbit OLED_SDA=P1^0; //
#define MAIN_Fosc 24000000UL
u8 code show1[]=
{
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",0*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,/*"9",9*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x1F,0x01,0x01,0x01,0x01,0x1F,0x00,/*"A",10*/
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,/*"D",11*/
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,/*"W",12*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,/*"O",13*/
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,/*"N",14*/
};
u8 code show2[]=
{
0x08,0x08,0x08,0x08,0x88,0x78,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
0x20,0x10,0x48,0x46,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,/*"左",0*/
0x08,0x08,0x08,0x08,0xC8,0x38,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
0x08,0x04,0x02,0x01,0xFF,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,0x00,/*"右",1*/
0x80,0x60,0xF8,0x07,0x00,0x04,0x74,0x54,0x55,0x56,0x54,0x54,0x74,0x04,0x00,0x00,
0x00,0x00,0xFF,0x00,0x03,0x01,0x05,0x45,0x85,0x7D,0x05,0x05,0x05,0x01,0x03,0x00,/*"停",2*/
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,
0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,/*"止",3*/
0x00,0x00,0x00,0xFC,0x44,0x44,0x44,0x45,0x46,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,
0x40,0x20,0x18,0x07,0x00,0xFC,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFC,0x00,0x00,/*"启",4*/
0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,
0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"动",5*/
0x00,0x04,0x84,0x84,0x94,0xE4,0x85,0x86,0x84,0xC4,0xB4,0x84,0x84,0x84,0x80,0x00,
0x80,0x60,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"产",6*/
0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00,
0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,/*"量",7*/
0x40,0x40,0x42,0xCC,0x00,0x80,0x88,0x88,0xFF,0x88,0x88,0xFF,0x88,0x88,0x80,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x4C,0x43,0x40,0x40,0x5F,0x40,0x40,0x40,0x00,/*"进",8*/
0x40,0x40,0x42,0xCC,0x00,0x00,0xFF,0x49,0x49,0xC9,0x49,0x49,0x7F,0x80,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x48,0x44,0x40,0x41,0x42,0x45,0x58,0x40,0x00,/*"退",9*/
0x00,0x00,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00,
0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,/*"刀",10*/
0x00,0x10,0x88,0xC4,0x33,0x40,0x48,0x48,0x48,0x7F,0x48,0xC8,0x48,0x48,0x40,0x00,
0x02,0x01,0x00,0xFF,0x00,0x02,0x0A,0x32,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x00,/*"待",11*/
0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x83,0x60,0x1F,0x00,0x00,0x00,0x3F,0x40,0x40,0x78,0x00,/*"机",12*/
};
//==========================================================================
/************* 本地常量声明 **************/
/************* IO口定义 **************/
/************* 本地变量声明 **************/
/************* 本地函数声明 **************/
void delay_ms(u8 ms);
/*************Pin Define***************/
void Initial_LY096BG30();
void Delay_50ms(u16 Del_50ms);
void fill_picture(u8 fill_Data);
void IIC_Start();
void IIC_Stop();
void Write_IIC_Command(u8 IIC_Command);
void Write_IIC_Data(u8 IIC_Data);
bit Write_IIC_Byte(u8 IIC_Byte);
/*******************IIC Start******************/
void IIC_Start()
{
OLED_SCL=high;
OLED_SDA=high;
_nop_();
OLED_SDA=low;
_nop_();_nop_();
OLED_SCL=low;
}
/*************IIC Stop*************************/
void IIC_Stop()
{
OLED_SDA=low;
_nop_();
OLED_SCL=high;
_nop_();_nop_();
OLED_SDA=high;
}
/*****************IIC Write byte***************/
bit Write_IIC_Byte(u8 IIC_Byte)
{
unsigned char i;
bit Ack_Bit; //应答信号
for(i=0;i<8;i++)
{
if(IIC_Byte & 0x80) //1?0?
OLED_SDA=high;
else
OLED_SDA=low;
OLED_SCL=high;
_nop_();_nop_();
OLED_SCL=low;
IIC_Byte<<=1; //loop
}
OLED_SDA=high; //释放IIC SDA总线为主器件接收从器件产生应答信号
_nop_();_nop_();
OLED_SCL=high; //第9个时钟周期
_nop_();_nop_();
Ack_Bit=OLED_SDA; //读取应答信号
OLED_SCL=low;
return Ack_Bit;
}
/*************IIC Write Command*****************/
void Write_IIC_Command(u8 IIC_Command)
{
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(u8 IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78);
Write_IIC_Byte(0x40); //write data
Write_IIC_Byte(IIC_Data);
IIC_Stop();
}
/***************设置参数显示******************/
void dis_Val1(u8 s)
{
u8 x,y;
u16 i=0;
u8 A1,A2,A3;
A1=s/100;
A2=(s-A1*100)/10;
A3=s-A1*100-A2*10;
for(y=0;y<2;y++) //百位显示
{
Write_IIC_Command(0XB4+y); //纵向页
Write_IIC_Command(0X00); //横向离左部边缘开始的距离
Write_IIC_Command(0X10); //横向第四个字
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A1*16]); //0--A字符表
}
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A2*16]);
}
}
for(y=0;y<2;y++) //十位显示
{
Write_IIC_Command(0XB4+y); //纵向页
Write_IIC_Command(0X00); //横向离左部边缘开始的距离
Write_IIC_Command(0X11); //横向第五个字
for(x=0;x<8;x++) //横向像素
{
Write_IIC_Data(show1[x+y*8+A3*16]);
}
}
}
/**************** 外部函数声明和外部变量声明 *****************/
/******************** 主函数 **************************/
void main(void)
{
WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
EAXFR = 1; //扩展寄存器(XFR)访问使能
CKCON = 0; //提高访问XRAM速度
P0M1 = 0x00; P0M0 = 0xff; //设置为推挽输出
P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口
P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口
P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口
P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口
P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口
P6M1 = 0x00; P6M0 = 0x00; //设置为准双向口
P7M1 = 0x00; P7M0 = 0x00; //设置为准双向口
P40 = 0; //LED Power On
while(1)
{
P00 = 0; //LED On
delay_ms(250);
P00 = 1; //LED Off
P01 = 0; //LED On
delay_ms(250);
P01 = 1; //LED Off
P02 = 0; //LED On
delay_ms(250);
P02 = 1; //LED Off
P03 = 0; //LED On
delay_ms(250);
P03 = 1; //LED Off
P04 = 0; //LED On
delay_ms(250);
P04 = 1; //LED Off
P05 = 0; //LED On
delay_ms(250);
P05 = 1; //LED Off
P06 = 0; //LED On
delay_ms(250);
P06 = 1; //LED Off
P07 = 0; //LED On
delay_ms(250);
P07 = 1; //LED Off
P10 = 0; //LED On
delay_ms(250);
P10 = 1; //LED Off
P11 = 0; //LED On
delay_ms(250);
P11 = 1; //LED Off
P12 = 0; //LED On
delay_ms(250);
P12 = 1; //LED Off
P13 = 0; //LED On
delay_ms(250);
P13 = 1; //LED Off
P14 = 0; //LED On
delay_ms(250);
P14 = 1; //LED Off
P15 = 0; //LED On
delay_ms(250);
P15 = 1; //LED Off
P16 = 0; //LED On
delay_ms(250);
P16 = 1; //LED Off
P17 = 0; //LED On
delay_ms(250);
P17 = 1; //LED Off
P20 = 0; //LED On
delay_ms(250);
P20 = 1; //LED Off
P21 = 0; //LED On
delay_ms(250);
P21 = 1; //LED Off
P22 = 0; //LED On
delay_ms(250);
P22 = 1; //LED Off
P23 = 0; //LED On
delay_ms(250);
P23 = 1; //LED Off
P24 = 0; //LED On
delay_ms(250);
P24 = 1; //LED Off
P25 = 0; //LED On
delay_ms(250);
P25 = 1; //LED Off
P26 = 0; //LED On
delay_ms(250);
P26 = 1; //LED Off
P27 = 0; //LED On
delay_ms(250);
P27 = 1; //LED Off
P30 = 0; //LED On
delay_ms(250);
P30 = 1; //LED Off
P31 = 0; //LED On
delay_ms(250);
P31 = 1; //LED Off
P32 = 0; //LED On
delay_ms(250);
P32 = 1; //LED Off
P33 = 0; //LED On
delay_ms(250);
P33 = 1; //LED Off
P34 = 0; //LED On
delay_ms(250);
P34 = 1; //LED Off
P35 = 0; //LED On
delay_ms(250);
P35 = 1; //LED Off
P36 = 0; //LED On
delay_ms(250);
P36 = 1; //LED Off
P37 = 0; //LED On
delay_ms(250);
P37 = 1; //LED Off
}
}
//========================================================================
// 函数: void delay_ms(unsigned char ms)
// 描述: 延时函数。
// 参数: ms,要延时的ms数, 这里只支持1~255ms. 自动适应主时钟.
// 返回: none.
// 版本: VER1.0
// 日期: 2013-4-1
// 备注:
//========================================================================
void delay_ms(u8 ms)
{
u16 i;
do{
i = MAIN_Fosc / 6000;
while(--i);
}while(--ms);
}
|
|