keil uvision 5二进制常量之前的语法错误

时间:2018-03-24 15:02:39

标签: c syntax binary constants keil

我正在尝试构建此代码。 但我不知道错误在哪里?我做错了什么?

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"

#define LCD_PORT GPIOC
#define LCD_RCC_GPIO RCC_AHB1Periph_GPIOC
#define LCD_E_Pin GPIO_Pin_12
#define LCD_RS_Pin GPIO_Pin_10

void delay(unsigned int s);
void lcd_init_gpio();
void lcd_write_data(u16 data);
void lcd_init();
void lcd_write_str(char*str);
void lcd_write_cmd(u16 cmd);
void lcd_set_cursor(int line,int pos);
void lcd_write_dec_xxx(uint16_t data);
void lcd_write_dec_xxx(uint16_t data);
void lcd_write_dec_xx(uint8_t data);
void lcd_write_dec_x(uint8_t data);
int main(void)
{
    lcd_init();
  while (1)
    {

    }
}

void delay(unsigned int s){
    while(--s > 0) {
        __NOP();
    }
}

const uint8_t lcd_2x16_decode[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

void lcd_write_dec_xxxx(uint16_t data){
    lcd_write_data(lcd_2x16_decode[(data / 1000) & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 1000) / 100) & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 1000) % 100) / 10 & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 1000) % 100) % 10 & 0x0F]);
}

void lcd_write_dec_xxx(uint16_t data){
    lcd_write_data(lcd_2x16_decode[(data / 100) & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 100) / 10) & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 100) % 10) & 0x0F]);
}

void lcd_write_dec_xx(uint8_t data){
    lcd_write_data(lcd_2x16_decode[((data % 100) / 10) & 0x0F]);
    lcd_write_data(lcd_2x16_decode[((data % 100) % 10) & 0x0F]);
}

void lcd_write_dec_x(uint8_t data) {
    lcd_write_data(lcd_2x16_decode[data]);
}
void lcd_init_gpio() {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
    GPIO_InitTypeDef init;
    init.GPIO_Mode = GPIO_Mode_Out_PP;
    init.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12;
    GPIO_Init(LCD_PORT,&init);
}
void lcd_write_data(u16 data) {
    GPIO_SetBits(LCD_PORT,data | LCD_E_Pin);
    delay(0xFFFF);
    GPIO_ResetBits(LCD_PORT,LCD_E_Pin | data);
}
void lcd_init() {
    lcd_init_gpio();
    int del = 99999;
    GPIO_ResetBits(LCD_PORT, LCD_RS_Pin);
    delay(del);
    lcd_write_data(0b00110000);
    delay(del);
    lcd_write_data(0b00110000);
    delay(del);
    lcd_write_data(0b00110000);
    delay(del);
    lcd_write_data(0b00111000);
    delay(del);
    lcd_write_data(0b00001111);
    delay(del);
    lcd_write_data(0b00000001);
    delay(del);
    lcd_write_data(0b00000110);
    delay(del);
    lcd_write_data(0b00000010);
    delay(del);
    GPIO_SetBits(LCD_PORT,LCD_RS_Pin);
}

void lcd_write_str(char*str) {
    do {
        lcd_write_data(*str);
    }while(*++str);
}
void lcd_write_cmd(u16 cmd) {
    GPIO_ResetBits(LCD_PORT,LCD_RS_Pin);
    lcd_write_data(cmd);
    GPIO_SetBits(LCD_PORT,LCD_RS_Pin);
}
void lcd_set_cursor(int line,int pos) {
    pos |= 0b10000000;
    if (line == 1) {
        pos += 0x40;
    }
    lcd_write_cmd(pos);
}
  

main.c(76):错误:#18:期望一个“)”lcd_write_data(0b00110000);

     

main.c(78):错误:#18:预期“)”lcd_write_data(0b00110000);

     

main.c(80):错误:#18:预期“)”lcd_write_data(0b00110000);

     

main.c(82):错误:#18:预期“)”lcd_write_data(0b00111000);

     

main.c(84):错误:#18:期望一个“)”lcd_write_data(0b00001111);

     

main.c(86):错误:#18:期望一个“)”lcd_write_data(0b00000001);

     

main.c(88):错误:#18:预期“)”lcd_write_data(0b00000110);

     

main.c(90):错误:#18:预期“)”lcd_write_data(0b00000010);

     

main.c(106):错误:#65:预期“;” pos | = 0b10000000;

1 个答案:

答案 0 :(得分:1)

Keil是否支持二进制常量? uVision 3并非this link。尝试将0b00110000替换为等效0x30,同样替换其他0b...值。 (Another support page

0b00110000 0x30
0b00110000 0x30
0b00110000 0x30
0b00111000 0x38
0b00001111 0x0f
0b00000001 0x01
0b00000110 0x06
0b00000010 0x02
0b10000000 0x80