Hi,
It looks like your first problem is that you're making assignments outside of a function - the "ch[16] = 0x0a" won't work. That would compile to actual code and would have to be inside a function. You could initialize the entire array where it's declared:
unsigned char ch[4] = {1, 2, 3, 4};
But you can't make assignments there. As for <iostream> and the namespace, those are C++ features. You're using a very low-end MCU with 4 KB of flash and 126 bytes of RAM. C++ really isn't an option at that level. In pure C you can certainly implement a Modbus sender in a device like that - my own implementation was 1234 bytes of flash and 229 of RAM + 64 bytes stack, and most of that was for buffering ADC samples, but if you don't have much embedded C experience you're not going to have a lot of margin on a device like that.
In your other thread you mentioned that you were trying to implement Modbus ASCII. The fact that you've got a CRC 16 function here makes me think you're implementing Modbus RTU, since Modbus ASCII uses just a simple arithmetic sum, but your attempt to initialize ch[16] with a linefeed character looks like a Modbus ASCII message. Which exactly are you trying to implement?
Also, if it's Modbus RTU you're going for, are you sure that's the right CRC 16 calculation? I can't see the whole thing but that doesn't look like the right polynomial. Is that maybe CRC-16-CCITT?
Scott