/* T6963c.c - Function-implementations Simple LowLevel T6963c Library without Drawing functions for Rect's, Circles, etc... The files should be self-explanatory. (c) Simon Kueppers. If you find a bug or if you have a question, feel free to Email me: simon.kueppers@stlcd.de */ #include "T6963c.h" #include //Set to 1 if you want to speedup the library //Set to 0 if you want to get small code-size #define T6963C_USE_INLINE 0 #define nop() asm volatile ("nop") //Macros for Bitbanging //#define T6963C_RESET_ENABLE T6963C_PORT_CTRL &= ~(1<> 0)); T6963cPutData((uint8_t) (T6963C_ADDR_GRAPHIC >> 8)); T6963cPutCmd(T6963C_CMD_SETGRAPHICHOME); //Set Graphics Area to T6963C_GRPH_COLS byte per line T6963cPutData(T6963C_GRPH_COLS); T6963cPutData(0); T6963cPutCmd(T6963C_CMD_SETGRAPHICAREA); //Set Text Home Address to 0x0800 T6963cPutData((uint8_t) (T6963C_ADDR_TEXT >> 0)); T6963cPutData((uint8_t) (T6963C_ADDR_TEXT >> 8)); T6963cPutCmd(T6963C_CMD_SETTEXTHOME); //Set Text Area to T6963C_TEXT_COLS columns T6963cPutData(T6963C_TEXT_COLS); T6963cPutData(0); T6963cPutCmd(T6963C_CMD_SETTEXTAREA); //Set Internal CGROM and XOR mode T6963cPutCmd(T6963C_CMD_MODESET | Options); //Set Display Mode T6963cPutCmd(T6963C_CMD_DISPMODE | Mode); //Set CGRAM Address to 1800-1FFF T6963cPutData(T6963C_ADDR_CGRAML >> 11); T6963cPutData(0); T6963cPutCmd(T6963C_CMD_SETOFFSET); //Clear Display T6963cClear(); //Reset some Addresses T6963cSetAddress(0); T6963cSetCursorXY(0, 0); } void T6963cCursorPattern(uint8_t Height) { T6963cPutCmd(T6963C_CMD_CURSORPATTERN | (Height - 1)); } void T6963cSetCursorXY(uint8_t X, uint8_t Y) { T6963cPutData(X); T6963cPutData(Y); T6963cPutCmd(T6963C_CMD_SETCURSOR); } void T6963cClear() { uint16_t i; //Clear Text RAM using AutoWriting T6963cSetAddress(T6963C_ADDR_TEXT); T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); for (i=0; i<(T6963C_TEXT_COLS * T6963C_TEXT_ROWS); i++) T6963cPutDataAW(0x00); T6963cPutCmd(T6963C_CMD_AUTORESET); //Clear Graphic RAM using AutoWriting T6963cSetAddress(T6963C_ADDR_GRAPHIC); T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); for (i=0; i<(T6963C_GRPH_COLS * T6963C_GRPH_ROWS); i++) T6963cPutDataAW(0x00); T6963cPutCmd(T6963C_CMD_AUTORESET); } void T6963cSetAddress(uint16_t Address) { //Send Address-LowByte, HighByte and Command T6963cPutData((uint8_t) (Address >> 0)); T6963cPutData((uint8_t) (Address >> 8)); T6963cPutCmd(T6963C_CMD_SETADDRESS); } void T6963cWrite(uint8_t Byte) { //Send Databyte and Command T6963cPutData(Byte); T6963cPutCmd(T6963C_CMD_WRITE_INC); } void T6963cWriteChunk(uint8_t* pBuffer, uint16_t nBytes) { //Initiate AutoWrite, write Data from RAM and escape AutoWrite-Mode T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); while (nBytes--) T6963cPutDataAW(*pBuffer++); T6963cPutCmd(T6963C_CMD_AUTORESET); } void T6963cWriteChunk_P(const prog_uint8_t* pBuffer, uint16_t nBytes) { //Initiate AutoWrite, write Data from Flash and escape AutoWrite-Mode T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); while (nBytes--) T6963cPutDataAW(pgm_read_byte(pBuffer++)); T6963cPutCmd(T6963C_CMD_AUTORESET); } void T6963cSetPixel(uint8_t Bit) { //OR Command with Pixelnumber and send Command T6963cPutCmd(T6963C_CMD_SETPIXEL | (Bit & 0x07)); } void T6963cResetPixel(uint8_t Bit) { //OR Command with Pixelnumber and send Command T6963cPutCmd(T6963C_CMD_RESETPIXEL | (Bit & 0x07)); } void T6963cPutChar(char Char) { //Subtract 0x20 (T6963c has a slightly different ASCII Charset), send as Data and send Command uint8_t c = Char; if (c < 0x80) c -= 0x20; T6963cPutData(c); T6963cPutCmd(T6963C_CMD_WRITE_INC); } void T6963cPutString(char* pString) { //Initiate AutoWrite. Then fetch each char from RAM and send, while the String has not ended. //escape AutoWrite-Mode when finished. uint8_t c; T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); while ((c = *pString++) != '\0') { if (c < 0x80) c -= 0x20; T6963cPutDataAW(c); } T6963cPutCmd(T6963C_CMD_AUTORESET); } void T6963cPutString_P(const prog_char* pString) { //Initiate AutoWrite. Then fetch each char from Flash and send, while the String has not ended. //escape AutoWrite-Mode when finished. uint8_t c; T6963cPutCmd(T6963C_CMD_AUTOWRITE); while ((T6963cGetStatus() & (T6963C_STA0 | T6963C_STA1)) != (T6963C_STA0 | T6963C_STA1)) nop(); while ((c = pgm_read_byte(pString++)) != '\0') { if (c < 0x80) c -= 0x20; T6963cPutDataAW(c); } T6963cPutCmd(T6963C_CMD_AUTORESET); } //--------------------------------------------------------------------- /*void T6963_print_str(char *str) { while (*str) { T6963cPutChar(*str++); }; }; */ //void T6963_print_Str(unsigned char zeile,unsigned char spalte, //int i = 25; // char Buffer[20]; // itoa( i, Buffer, 10 ); // lcd_string( Buffer ); // ggf. auch lcd_out() o.ä. in anderen Libraries //--------------------------------------------------------------------- /*void T6963_print_P (unsigned char zeile,unsigned char spalte,const char *Buffer,...) { va_list ap; va_start (ap, Buffer); int format_flag; char str_buffer[10]; char str_null_buffer[10]; char move = 0; char Base = 0; int tmp = 0; char by; char *ptr; //Berechnet Adresse für die Zeile und schreibt sie ins DD-Ram //zeile = LINE_ADDRESS[zeile]; //zeile += spalte; //lcd_write(zeile,0); //T6963cSetAddress(T6963C_ADDR_TEXT + (T6963C_TEXT_COLS * (zeile)) + (spalte)); //Ausgabe der Zeichen for(;;) { by = pgm_read_byte(Buffer++); if(by==0) break; // end of format string if (by == '%') { by = pgm_read_byte(Buffer++); if (isdigit(by)>0) { str_null_buffer[0] = by; str_null_buffer[1] = '\0'; move = atoi(str_null_buffer); by = pgm_read_byte(Buffer++); } switch (by) { case 's': ptr = va_arg(ap,char *); while(*ptr) { T6963cPutCharXY(zeile, spalte, (*ptr++)); }//lcd_write(*ptr++,1); } break; case 'b': Base = 2; goto ConversionLoop; case 'c': //Int to char format_flag = va_arg(ap,int); T6963cPutCharXY(zeile, spalte, (format_flag++));// (format_flag++,1); break; case 'i': Base = 10; goto ConversionLoop; case 'o': Base = 8; goto ConversionLoop; case 'x': Base = 16; ConversionLoop: itoa(va_arg(ap,int),str_buffer,Base); int b=0; while (str_buffer[b++] != 0){}; b--; if (b