123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #include <util/delay.h>
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include <avr/wdt.h>
- #include "sed1335.h"
- //config data is set in sed1335.h
- void GLCD_Initialize(void){
- GLCD_InitializePorts();
- GLCD_HardReset();
- GLCD_WriteCommand(SED1335_SYSTEM_SET);
- _delay_ms(10);
- GLCD_WriteData(SED1335_SYS_P1);
- GLCD_WriteData(SED1335_SYS_P2);
- GLCD_WriteData(SED1335_FY);
- GLCD_WriteData(SED1335_CR);
- GLCD_WriteData(SED1335_TCR);
- GLCD_WriteData(SED1335_LF);
- GLCD_WriteData(SED1335_AP & 0xff);
- GLCD_WriteData(SED1335_AP >> 8);
- GLCD_WriteCommand(SED1335_SCROLL);
- GLCD_WriteData(SED1335_SAD1 & 0xff);
- GLCD_WriteData(SED1335_SAD1 >> 8);
- GLCD_WriteData(SED1335_SL1);
- GLCD_WriteData(SED1335_SAD2 & 0xff);
- GLCD_WriteData(SED1335_SAD2 >> 8);
- GLCD_WriteData(SED1335_SL2);
- GLCD_WriteData(SED1335_SAD3 & 0xff);
- GLCD_WriteData(SED1335_SAD3 >> 8);
- GLCD_WriteData(SED1335_SAD4 & 0xff);
- GLCD_WriteData(SED1335_SAD4 >> 8);
-
- GLCD_WriteCommand(SED1335_CSRFORM);
- GLCD_WriteData(SED1335_CRX);
- GLCD_WriteData(SED1335_CSRF_P2);
-
- GLCD_WriteCommand(SED1335_CGRAM_ADR);
- GLCD_WriteData(SED1335_SAG & 0xff);
- GLCD_WriteData(SED1335_SAG >> 8);
-
- GLCD_WriteCommand(SED1335_CSRDIR_R);
- GLCD_WriteCommand(SED1335_HDOT_SCR);
- GLCD_WriteData(SED1335_SCRD);
-
- GLCD_WriteCommand(SED1335_OVLAY);
- GLCD_WriteData(SED1335_OVLAY_P1);
- GLCD_WriteCommand(SED1335_GRAYSCALE);
- GLCD_WriteData(SED1335_BPP);
-
- GLCD_WriteCommand(SED1335_DISP_ON);
- GLCD_WriteData(SED1335_FLASH);
- GLCD_Clear();
- }
- //internal functions
- void GLCD_InitializePorts(void){
- SED1335_DATA_DIR = 0xFF;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT |= SED1335_CS;
- SED1335_CONTROL_DIR |= SED1335_CS;
- #endif
- SED1335_CONTROL_PORT |= (SED1335_WR
- #ifdef SED1335_RD
- | SED1335_RD
- #endif
- | SED1335_RES);
- SED1335_CONTROL_DIR |= (SED1335_A0 | SED1335_WR
- #ifdef SED1335_RD
- | SED1335_RD
- #endif
- | SED1335_RES);
- SED1335_RST_PORT |= SED1335_RES;
- SED1335_RST_DIR |= SED1335_RES;
- }
- void GLCD_WriteData(unsigned char dataToWrite){
- #ifdef SED1335_DISABLE_INT
- cli();
- #endif
- SED1335_DATA_PORT = dataToWrite;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT &= ~SED1335_CS;
- #endif
- SED1335_CONTROL_PORT &= ~SED1335_WR;
- asm("nop");
- SED1335_CONTROL_PORT |= SED1335_WR;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT |= SED1335_CS;
- #endif
- #ifdef SED1335_DISABLE_INT
- sei();
- #endif
- }
- void GLCD_WriteCommand(unsigned char commandToWrite){
- SED1335_CONTROL_PORT |= SED1335_A0;
- #ifdef SED1335_DISABLE_INT
- cli();
- #endif
- SED1335_DATA_PORT = commandToWrite;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT &= ~SED1335_CS;
- #endif
- SED1335_CONTROL_PORT &= ~SED1335_WR;
- asm("nop");
- SED1335_CONTROL_PORT |= SED1335_WR;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT |= SED1335_CS;
- #endif
- #ifdef SED1335_DISABLE_INT
- sei();
- #endif
- SED1335_CONTROL_PORT &= ~SED1335_A0;
- }
- /*unsigned char GLCD_ReadData(void){
- unsigned char tmp;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT &= ~SED1335_CS;
- #endif
- SED1335_CONTROL_PORT |= SED1335_A0;
- #ifdef SED1335_DISABLE_INT
- cli();
- #endif
- SED1335_DATA_DIR = 0x00;
- SED1335_CONTROL_PORT &= ~SED1335_RD;
- asm("nop");
- tmp = SED1335_DATA_PIN;
- SED1335_CONTROL_PORT |= SED1335_RD;
- #ifdef SED1335_CS
- SED1335_CONTROL_PORT |= SED1335_CS;
- #endif
- #ifdef SED1335_DISABLE_INT
- sei();
- #endif
- SED1335_CONTROL_PORT &= ~SED1335_A0;
- return tmp;
- }*/
- void GLCD_HardReset(void){
- wdt_reset();
- _delay_ms(150);
- wdt_reset();
- SED1335_RST_PORT &= ~(SED1335_RES);
- _delay_ms(20);
- SED1335_RST_PORT |= (SED1335_RES);
- _delay_ms(20);
- wdt_reset();
- }
- //external LCD access functions
- /*void GLCD_Clear(void){ //używam swojej w gtext.c
- GLCD_ClearText();
- GLCD_ClearGraphic();
- }*/
- /*void GLCD_SetPixel(unsigned int x,unsigned int y, int color){ //nietestowane!
- unsigned char tmp = 0;
- unsigned int address = SED1335_GRAPHICSTART + (40 * y) + (x/8);
- GLCD_SetCursorAddress(address);
- GLCD_WriteCommand(SED1335_MREAD);
- tmp = GLCD_ReadData();
- if(color)
- tmp |= (1 << (SED1335_FX - (x % 8)));
- else
- tmp &= ~(1 << (SED1335_FX - (x % 8)));
- GLCD_SetCursorAddress(address);
- GLCD_WriteCommand(SED1335_MWRITE);
- GLCD_WriteData(tmp);
- }*/
- // funkcje do trybu tekstowego - nie używam
- /*void GLCD_WriteText(char * tekst){
- GLCD_WriteCommand(SED1335_MWRITE);
- while(*tekst)
- GLCD_WriteData(*tekst++);
- }*/
- /*void GLCD_WriteTextP(char * tekst){
- GLCD_WriteCommand(SED1335_MWRITE);
- while(pgm_read_byte(tekst))
- GLCD_WriteData(GLCD_ReadByteFromROMMemory(tekst++));
- }*/
- /*void GLCD_TextGoTo(unsigned char x, unsigned char y){
- GLCD_SetCursorAddress((y * 40) + x);
- }*/
- /*void GLCD_ClearText(void){
- int i;
- GLCD_TextGoTo(0,0);
- GLCD_WriteCommand(SED1335_MWRITE);
- for(i = 0; i < 1200; i++)
- GLCD_WriteData(' ');
- }*/
- void GLCD_SetCursorAddress(unsigned int address){
- GLCD_WriteCommand(SED1335_CSRW);
- GLCD_WriteData((unsigned char)(address & 0xFF));
- GLCD_WriteData((unsigned char)(address >> 8));
- }
- // funkcje do trybu graficznego - używam własnych w gtext.c
- /*void GLCD_GraphicGoTo(unsigned int x, unsigned int y){
- GLCD_SetCursorAddress(SED1335_GRAPHICSTART + (y * 80) + x*2);
- }*/
- /*void GLCD_ClearGraphic(void){
- unsigned int i;
- GLCD_SetCursorAddress(SED1335_GRAPHICSTART);
- GLCD_WriteCommand(SED1335_MWRITE);
- for(i = 0; i < SED1335_GRAPHICSIZE; i++) //zweryfikuj przed użyciem, czy dobra strona!!!
- GLCD_WriteData(0x00);
- clearbg();
- }*/
- /*void GLCD_Bitmap(char * bmp, int x, int y, int width, int height){ //nietestowane
- unsigned int i, j;
- for(i = 0; i < height ; i++){
- GLCD_GraphicGoTo(x, y+i);
- GLCD_WriteCommand(SED1335_MWRITE);
- for(j = 0; j < width/8; j++)
- GLCD_WriteData(pgm_read_byte(bmp+j+(40*i)));
- }
- }*/
|