关于函数指针,数组,&的例子

1.显示函数 void OLED_ShowString(u8 x,u8 y,const u8 *p)

调用:(1)OLED_ShowString(0,16,"ATOM@ALIENTEK");,正常显示;

        (2)定义 u8 Temp[3]={"123"};     0位1, 1位2  ,2位3

                 a,OLED_ShowString(0,0,&Temp[0]);显示  123;

                 b,OLED_ShowString(0,0,&Temp[1]); 显示23;

                 c.OLED_ShowString(0,0,&Temp);或者OLED_ShowString(0,0,Temp[0]);编译出错。

         (3)定义 u8 Temp[3]={"23"};  0位2,1位3

                a,OLED_ShowString(0,0,&Temp[0]);显示  23;

                b,OLED_ShowString(0,0,&Temp[1]); 显示3;

         (4)去除大括号,直接定义u8 Temp[]="123";    

             则  OLED_ShowString(0,0,&Temp[0]);和 OLED_ShowString(0,0,Temp) 均可;

         (5)强制字符转换sprintf;  定义    char Temp[3];  u16 num=123;

                                                 sprintf(Temp, (const char *)"%d",num); 

                                                a,    OLED_ShowString(0,0,(const char *)&Temp[0]);    显示123

                                                b,  OLED_ShowString(0,0,(const char *)&Temp[1]);    显示23

                                                c.    若把num=12345, 也能成功显示12345;

比较 2.  函数   void Asc8_16(unsigned char x,unsigned char y,unsigned char ch[])

           调用方法与1相同

 

3.函数 void SPI_Flash_Write_NoCheck(u8* pBuffer,u32 WriteAddr,u16 NumByteToWrite)  

调用  (1)写入整个数组  const u8 TEXT_Buffer[]={"WarShipSTM32 SPI TEST"};  或者  const u8 TEXT_Buffer[32]={0x01,0x00,0x00,0x80,0x3F,0xFE,0x20,0x00。。。。。}

                  则    SPI_Flash_Write((u8*)TEXT_Buffer,FLASH_SIZE-100,32); (括号里的u8*去除会报错)

          (2)写入一个数据    u8 temp; 则  SPI_Flash_Write_NoCheck(&temp,Write_Address++,1); 

4.读取函数 void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead) 

   调用: 定义  u8 datatemp[32];           SPI_Flash_Read(datatemp,FLASH_SIZE-100,32);  

 

posted on 2016-09-06 16:22  马小跳life  阅读(570)  评论(0编辑  收藏  举报

导航