找回密码
 立即注册
查看: 21|回复: 2

AI8051数据类型

[复制链接]
  • 打卡等级:偶尔看看II
  • 打卡总天数:27
  • 最近打卡:2025-09-02 20:41:47

34

主题

97

回帖

938

积分

高级会员

积分
938
发表于 昨天 20:41 | 显示全部楼层 |阅读模式
    刚刚焊了一块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);
}



回复

使用道具 举报 送花

3

主题

2001

回帖

850

积分

等待验证会员

积分
850
发表于 昨天 20:43 | 显示全部楼层
关于AI8051数据类型及编译警告问题的说明如下:

在使用AI8051系列芯片进行开发时,正确理解和使用数据类型是保证程序稳定运行的基础。当前用户在测试过程中遇到的“parameter 1: value truncated”警告,主要源于对u8类型与常量值之间的匹配问题。

首先,AI8051平台支持的标准数据类型包括:u8(无符号8位整型)、s8(有符号8位整型)、u16(无符号16位整型)、s16(有符号16位整型)等,这些类型在编译器中均被严格定义为对应长度的数值范围。其中,u8的取值范围为0~255(即0x00~0xFF),超出该范围的数值将导致截断(truncated)现象。

在用户提供的代码片段中,WriteIICCommand(0XB4+y);这一语句存在潜在风险。虽然y可能是一个u8类型的变量,但0xB4本身是一个十六进制常量,其十进制值为180,属于u8的有效范围。然而,如果y的值超过75(即0xB4 + y > 0xFF),则会导致参数溢出,从而触发编译器警告。

建议用户检查y的取值范围,并确保其与0xB4相加后的结果不超过255。例如,可添加边界判断逻辑或调整计算方式,以避免数据截断。

此外,关于USB下载功能,AI8051U系列芯片支持通过USB LINK1D工具实现固件更新。若使用的是早期版本的AI8051芯片(如春节购买的5片),由于固件未集成USB下载功能,需依赖外部烧录工具完成程序加载。建议用户确认所用芯片的型号和固件版本,以确保兼容性。

综上所述,AI8051的数据类型管理及编译警告处理是开发过程中不可忽视的环节。合理使用数据类型、严格控制数值范围,能够有效提升程序的稳定性和可靠性。如有进一步技术问题,欢迎联系国芯人工智能技术支持团队。

[本文内容由国芯人工智能辅助生成,仅供参考]
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看II
  • 打卡总天数:27
  • 最近打卡:2025-09-02 20:41:47

34

主题

97

回帖

938

积分

高级会员

积分
938
发表于 昨天 21:17 | 显示全部楼层
         用了一个障眼法
        先定义一个变量Z
并且赋初值0XB4;
执行完语句Write_IIC_Command
再加Y地址
              z=0XB4;
               for(y=0;y<2;y++)                  //百位显示
               {
               Write_IIC_Command(z);        //纵向页    1011
               z=y+0XB4;

但是OLED 还没有显示
今天奔波了一天
明天继续

/******************************************/

#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^0;         //
              sbit         OLED_SDA=P1^1;         //
#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*/
};
//==========================================================================
void  delay_ms(u8 ms);

void  Oled_delay(u8 ms)
{
      u8 i,j;
              for(i=0;i<ms;i++)
              for(j=0;j<80;j++);
}
/*************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;
               Oled_delay(2);
               OLED_SDA=low;
              Oled_delay(2);
               OLED_SCL=low;
              }
/*************IIC Stop*************************/
              void IIC_Stop()
              {
              OLED_SDA=low;
              Oled_delay(2);
              OLED_SCL=high;
              Oled_delay(2);
              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;
               Oled_delay(2);
               OLED_SCL=low;
               IIC_Byte<<=1;                     //loop
               }
              OLED_SDA=high;                     //释放IIC SDA总线为主器件接收从器件产生应答信号   
              Oled_delay(2);
              OLED_SCL=high;                     //第9个时钟周期
             Oled_delay(2);
              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,z;
               u16 i=0;
               u8 A1,A2,A3;
               A1=s/100;
               A2=(s-A1*100)/10;
               A3=s-A1*100-A2*10;
               z=0XB4;
               for(y=0;y<2;y++)                  //百位显示
               {
               Write_IIC_Command(z);        //纵向页    1011
               z=y+0XB4;
               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]);
                }
               }
                z=0XB4;
                for(y=0;y<2;y++)                 //十位显示
                {
                Write_IIC_Command(z);       //纵向页
                z=y+0XB4;
                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)
    {
        dis_Val1(0X12);
        P30 = 0;        //LED On
        delay_ms(2500);
        P30 = 1;        //LED Off
        dis_Val1(0X12);
        P31 = 0;        //LED On
        delay_ms(2500);
        P31 = 1;        //LED Off
        dis_Val1(0X16);
        P32 = 0;        //LED On
        delay_ms(2500);
        P32 = 1;        //LED Off
        dis_Val1(0X18);
        P33 = 0;        //LED On
        delay_ms(2500);
        P33 = 1;        //LED Off
        dis_Val1(0X20);
        }
}

//========================================================================
// 函数: 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);
}


回复

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-9-3 04:49 , Processed in 0.125722 second(s), 59 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表