Thread: Annoying programming errors

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    1

    Annoying programming errors

    Hi there

    I have to confess at the outset that I am not a great programmer but slowly learning!

    I am trying to tweak the code found in this application not for a product made by 4d systems - http://www.4dsystems.com.au/download...-host-REV1.pdf The example code starts on page 16.

    I am trying to hook a microcontroller written with C up to the display. My first step is to create 3 simple functions - sendmessage, readmessage and nacack.

    Here is the code that I have got thus far -

    Code:
    #define READ_OBJ 0x00
    #define WRITE_OBJ 0x01
    #define REPORT_OBJ 0x05
    #define REPORT_EVENT 0x07
    
    const unsigned int led0 = 0x0F00;    // Leddigit0
    unsigned short command;
    unsigned int object, value;
    bit flag;
    
    
    void main() {
       UART1_init(9600);
    
       while(1){                                    // Endless loop
       sendMessage(WRITE_OBJ, 0x0F00, 1);
       delay_ms(500);
       }
    
    }
    
    bit sendMessage(unsigned short command0, unsigned int object0, unsigned int value0) {
    bit flag0 = 0 ;
    unsigned short buffer[6];
    unsigned short checksum = 0x00;
    unsigned short i = 0;
    
    buffer[i] = command0;
    checksum = command0;
    i++;
    buffer[i] = object0 >> 8;
    checksum ^= buffer[i];
    i++;
    
    buffer[i] = object0 & 0xff;
    checksum ^= buffer[i];
    i++;
    buffer[i] = value0 >> 8;
    checksum ^= buffer[i];
    i++;
    buffer[i] = value0 & 0xff;
    checksum ^= buffer[i];
    i++;
    buffer[i] = checksum;
    i++;
    
    UART_write(buffer[0]);
    UART_write(buffer[1]);
    UART_write(buffer[2]);
    UART_write(buffer[3]);
    UART_write(buffer[4]);
    UART_write(buffer[5]);
    UART_write(buffer[6]);
    
    delay_ms(1000);
    
    return(nacAck()==0x06);
    
    }
    
    
    unsigned short nacAck() {
    unsigned short receive;
    delay_ms(10);
    while (UART_Data_Ready() == 0)
    receive = UART_Read();
    return UART1_Read();    // 0x06 or 0xd5
    }
    
    bit readMessage(unsigned short &command0, unsigned int &object0, unsigned int &value0) {
    bit flag0 = 0;
    unsigned short buffer[6];
    unsigned short checksum = 0x00;
    unsigned short i = 0;
    
    if (UART_Data_Ready() == 1) {
        buffer[i] = UART_Read();
        command0 = buffer[0];
        i++;
        checksum = command0;
    
        if (command0 == REPORT_EVENT) {
            if (UART_Data_Ready() == 1) {             //should be if number of bytes available is greater than 3
                buffer[i] = UART_Read();
                checksum ^= buffer[i];
                i++;
                buffer[i] = UART_Read();
                checksum ^= buffer[i];
                i++;
                object0 = buffer[1]<<8 | buffer[2];
                buffer[i] = UART_Read();
                checksum ^= buffer[i];
                i++;
                object0 = buffer[1]<<8 | buffer[2];
                buffer[i] = UART_Read();
                checksum ^= buffer[i];
                i++;
                value0 = buffer[3]<<8 | buffer[4];
            }
        }
        flag0 = (checksum==1);
    }
    return flag0;
    
    }
    I keep getting errors when I realise must come from 1 or 2 stupid mistakes. Namely around the calling/passing for variables to functions probably to do with the pointers (line number 16, 70, 71). And also around the returning value from the function which is meant to return true or false depending on the result of nacack (line number 57). I realise that there are also some errors to do with the UART functions but I am trying to resolve the errors pointed out above and then I will have a look at them.

    16 Undeclared identifier 'sendMessage' in expression testbox.c
    22 Function must not have return value of bit or sbit type 4dcode.c
    57 Undeclared identifier 'nacAck' in expression 4dcode.c
    57 Operator '' is not applicable to these operands '' 4dcode.c
    70 Syntax Error: ')' expected, but '&' found 4dcode.c
    70 Invalid declarator expected'(' or identifier 4dcode.c
    70 Invalid declarator expected'(' or identifier 4dcode.c
    71 '' Identifier redefined testbox.c
    70 Function must not have return value of bit or sbit type 4dcode.c
    76 Specifier needed testbox.c
    76 Invalid declarator expected'(' or identifier 4dcode.c
    76 Syntax Error: ')' expected, but '(' found 4dcode.c
    77 Internal error '' 4dcode.c

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,580
    For the first error you need to declare your function before you try to use it.

    For the second error it seems your compiler doesn't allow you tho use the bit or sbit types as return values from your functions.

    For the third, where is the function nacAck'() declared and implemented?

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming Assignment Help!! (Cant Figure Out My Errors) :(
    By irishfeeney92 in forum C Programming
    Replies: 19
    Last Post: 04-28-2011, 02:14 PM
  2. programming errors
    By C_Enthuaist in forum C Programming
    Replies: 15
    Last Post: 07-02-2010, 01:32 PM
  3. How do I fix these annoying warnings and errors?
    By zyphirr in forum C Programming
    Replies: 18
    Last Post: 11-12-2008, 06:19 PM
  4. Errors, with vectors, windows programming... etc
    By bobbelPoP in forum C++ Programming
    Replies: 10
    Last Post: 07-27-2008, 03:07 AM
  5. So annoying. How to do it?
    By Hugo716 in forum C++ Programming
    Replies: 24
    Last Post: 06-16-2006, 05:07 PM