Step 8Writing to the display from host software
All communication with the device is done with the function SendData( int request, int data ). This function is actually a shorted version of a function named usb_control_msg. We use the shorted version because the usb_control_msg is really long and messy. (The SendData function is defined in the USBFunctions.cpp file.)
I have defined all the request codes I have made with names, but you may use numbers if you like.
If you want to write pixels to the screen, use the SendData( SEND_DATA, data ) function, and replace the "data" with a 1 byte int. This will write 8 pixels on the current XY location. Keep in mind that it taks a long time to write a lot of pixels to the screen using this method. If you want to draw many pixels really fast, you should embed that code on the chip itself.
To send a command, use the SendData( SEND_COMMAND, data ) function, and replace the "data" with a command
(See the LCD dataseet for commands, page 14)
To clear the screen, use the SendData( SEND_CLEAR, 0 ) function. This will make the AVR draw 0 to all pixels on the screen. It is much faster to let the AVR do this, than doing it manually via host software. This obviously needs no extra data then the request itself.
If you want to specify an XY location to write to, use SendData( SEND_XY, ( y << 8 ) + x ). Replace the Y with a number between 0 and 5, and the X with a number between 0 and 83. This sends 2 bytes to the AVR, and that's the reason we shift the Y by 8 (So the Y value is at the 2nd byte).
To send an ASCII character to the screen, use SendData( SEND_CHAR, data ). Note that characters must be in single quotes, e.g.: SendData( SEND_CHAR, 'A' ).
If you'd like to write a lot of characters, you can store the string in an array and use a loop, like this:
unsigned char buffer[] = {"MY STRING12341!!\n"};
for(int j = 0;j < sizeof(buffer)-1;++j){
SendData(SEND_CHAR, buffer[j]);
}
Note that you can use the newline( \n ) to jump to the next line on the Y axis. It will save you a lot of trouble.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|










































