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

标签 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): error: #18: expected a ")" lcd_write_data(0b00110000);

main.c(78): error: #18: expected a ")" lcd_write_data(0b00110000);

main.c(80): error: #18: expected a ")" lcd_write_data(0b00110000);

main.c(82): error: #18: expected a ")" lcd_write_data(0b00111000);

main.c(84): error: #18: expected a ")" lcd_write_data(0b00001111);

main.c(86): error: #18: expected a ")" lcd_write_data(0b00000001);

main.c(88): error: #18: expected a ")" lcd_write_data(0b00000110);

main.c(90): error: #18: expected a ")" lcd_write_data(0b00000010);

main.c(106): error: #65: expected a ";" pos |= 0b10000000;

最佳答案

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

关于c - 二进制常量前的keil uvision 5语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49466203/

相关文章:

c - 如何有效地知道字符中第一个(左 ->右) '1'位的位置

c++ - OpenCV图像阵列,4D矩阵

C++ - 包括 unistd.h : why not cunistd?

c++ - 字符串值与 C++ 不匹配

javascript - 在 Javascript (Ajax) 中检索二进制数据

c - `fwrite()` 后的最后一个字节是什么意思?

python - 我正在尝试找到第 n 个二进制回文

C 程序链接错误?

language-agnostic - Map 键和值之间的符号是否有独立于语言的名称?

java - 编码错误导致死循环