int8_t LCDWriteInt(int val,int8_t field_length) { char str[5]={-16,-16,-16,-16,-16}; int i=4,j=0; if(val == 0) { str[4] = 0; } //Handle negative integers if(val<0) { LCDData('-'); //Write Negative sign val=val*-1; //convert to positive } while(val) { str[i]=val%10; val=val/10; i--; } if(field_length==-1) while(str[j]==-16) j++; else j=5-field_length; for(i=j;i<5;i++) { LCDData(48+str[i]); } return field_length; }
//Usage: LCDSetPixel(white, 0, 0); //Inputs: unsigned char color - desired color of the pixel // unsigned char x - Page address of pixel to be colored // unsigned char y - column address of pixel to be colored //Outputs: None //Description: Sets the starting page(row) and column (x & y) coordinates in ram, // then writes the colour to display memory. The ending x & y are left // maxed out so one can continue sending colour data bytes to the 'open' // RAMWR command to fill further memory. issuing any red command // finishes RAMWR. //**NOTE** Because this function is static, it is essentially a "private" function // and can only be used within this file! void LCDSetPixel(int color, unsigned char x, unsigned char y) { #ifdef EPSON LCDCommand(PASET); // page start/end ram LCDData(x); LCDData(ENDPAGE); LCDCommand(CASET); // column start/end ram LCDData(y); LCDData(ENDCOL); LCDCommand(RAMWR); // write LCDData((color>>4)&0x00FF); LCDData(((color&0x0F)<<4)|(color>>8)); LCDData(color&0x0FF); // nop(EPSON) //LCDData(color); //LCDData(NOP); //LCDData(NOP); #endif #ifdef PHILLIPS LCDCommand(PASETP); // page start/end ram LCDData(x); LCDData(ENDPAGE); LCDCommand(CASETP); // column start/end ram LCDData(y); LCDData(ENDCOL); LCDCommand(RAMWRP); // write LCDData((unsigned char)((color>>4)&0x00FF)); LCDData((unsigned char)(((color&0x0F)<<4)|0x00)); #endif }
void LCDWriteInt(int val,unsigned int field_length) { /*************************************************************** This function writes a integer type value to LCD module Arguments: 1)int val : Value to print 2)unsigned int field_length :total length of field in which the value is printed must be between 1-5 if it is -1 the field length is no of digits in the val ****************************************************************/ char str[5]={0,0,0,0,0}; int i=4,j=0; while(val) { str[i]=val%10; val=val/10; i--; } if(field_length==-1) while(str[j]==0) j++; else j=5-field_length; if(val<0) LCDData('-'); for(i=j;i<5;i++) { LCDData(48+str[i]); } }
/***************************************************************** This function Writes a given string to lcd at the current cursor location. Arguments: msg: a null terminated C style string to print Their are 8 custom char in the LCD they can be defined using "LCD Custom Character Builder" PC Software. You can print custom character using the % symbol. For example to print custom char number 0 (which is a degree symbol), you need to write LCDWriteString("Temp is 30%0C"); ^^ |----> %0 will be replaced by custom char 0. So it will be printed like. Temp is 30°C In the same way you can insert any symbols numbered 0-7 *****************************************************************/ int8_t LCDWriteString(const char *msg) { int8_t count = 0; while(*msg!='\0') { //Custom Char Support if(*msg=='%') { msg++; int8_t cc=*msg-'0'; if(cc>=0 && cc<=7) { LCDData(cc); count++; } else { LCDData('%'); count++; LCDData(*msg); count++; } } else { LCDData(*msg); count++; } msg++; } return count; }
void LCD_SendData(char data_value) // send data function the same as command (actually sending occur @ function LCDData) { char data_value1; data_value1=data_value&0xF0; LCDData(data_value1); data_value1=((data_value<<4)&0xF0); LCDData(data_value1); _delay_ms(200); }
void LCDWriteString(const char *msg) { /***************************************************************** This function Writes a given string to lcd at the current cursor location. Arguments: msg: a null terminated string to print Their are 8 custom char in the LCD they can be defined using "LCD Custom Character Builder" PC Software. You can print custom character using the % symbol. For example to print custom char number 0 (which is a degree symbol), you need to write LCDWriteString("Temp is 30%0C"); ^^ |----> %0 will be replaced by custom char 0. So it will be printed like. Temp is 30°C In the same way you can insert any syblom numbered 0-7 *****************************************************************/ while(*msg!='\0') { //Custom Char Support if(*msg=='%') { msg++; int8_t cc=*msg-'0'; if(cc>=0 && cc<=7) { LCDData(cc); } else { LCDData('%'); LCDData(*msg); } } else { LCDData(*msg); } msg++; } }
//Usage: LCDClear(black); //Inputs: char color: 8-bit color to be sent to the screen. //Outputs: None //Description: This function will clear the screen with "color" by writing the // color to each location in the RAM of the LCD. void LCDClear(int color) { #ifdef EPSON LCDCommand(PASET); LCDData(0); LCDData(131); LCDCommand(CASET); LCDData(0); LCDData(131); LCDCommand(RAMWR); #endif #ifdef PHILLIPS LCDCommand(PASETP); LCDData(0); LCDData(131); LCDCommand(CASETP); LCDData(0); LCDData(131); LCDCommand(RAMWRP); #endif for(unsigned int i=0; i < (131*131)/2; i++) { LCDData((color>>4)&0x00FF); LCDData(((color&0x0F)<<4)|(color>>8)); LCDData(color&0x0FF); // nop(EPSON) } x_offset = 0; y_offset = 0; }
void LCDCharacter(char character) { LCDData(0x00); //for (int index = 0 ; index < 5 ; index++) //LCDData(ASCII[character - 0x20][index]); for (int index = 0 ; index < 5 ; index++) //Reverse Bits on ASCII table. Mirrors characters, LCDDataChar sends LSB. LCDDataChar(reverse(ASCII[character - 0x20][4-index])); LCDData(0x00); }
void showTime() { LCDWriteInt(hour,2); LCDData(':') ; LCDWriteInt(minute,2); LCDData(':') ; LCDWriteInt(seconds,2); // setLED(0,minute / 10) ; // setLED(1,minute % 10) ; // setLED(2,seconds / 10) ; // setLED(3,seconds % 10) ; }
void LCDPrint(char *str){ unsigned int i=0; while(str[i]!='\0') { LCDData(str[i]); // sending data on LCD byte by byte i++; } }
void ColorLCDShield::contrast(char setting) { LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness(EPSON) LCDData(setting); // volume (contrast) setting - course adjustment, -- original was 24 LCDCommand(NOP); // nop(EPSON) }
void LCDShield::contrast(char setting) { if (driver == EPSON) { setting &= 0x3F; // 2 msb's not used, mask out LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness(EPSON) LCDData(setting); // volume (contrast) setting - course adjustment, -- original was 24 LCDData(3); // TODO: Make this coarse adjustment variable, 3's a good place to stay } else if (driver == PHILIPS) { setting &= 0x7F; // msb is not used, mask it out LCDCommand(SETCON); // contrast command (PHILLIPS) LCDData(setting); // volume (contrast) setting - course adjustment, -- original was 24 } }
void LCDInit(uint8_t style) { /***************************************************************** This function Initializes the lcd module must be called before calling lcd related functions Arguments: style = LS_BLINK,LS_ULINE(can be "OR"ed for combination) LS_BLINK : The cursor is blinking type LS_ULINE : Cursor is "underline" type else "block" type LS_NONE : No visible cursor *****************************************************************/ //After power on Wait for LCD to Initialize __delay_ms(30); //Set IO Ports LCD_DATA_TRIS&=(~(0x0F<<LCD_DATA_POS)); //Output LCD_E_TRIS=0; //Output LCD_RS_TRIS=0; //Output LCD_RW_TRIS=0; //Output LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));//Clear data port CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set 4-bit mode __delay_us(0.5); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 __delay_us(1); CLEAR_E(); __delay_us(1); //Wait for LCD to execute the Functionset Command LCDBusyLoop(); //[B] Forgot this delay //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001100|style); //Display On /* Custom Char */ LCDCmd(0b01000000); uint8_t __i; for(__i=0;__i<sizeof(__cgram);__i++) LCDData(__cgram[__i]); }
void LCDShield::contrast(char setting) { if(driver) LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness(EPSON) else LCDCommand(SETCON); // this is the contrast (PHILLIPS) LCDData(setting); // volume (contrast) setting - course adjustment, -- original was 24 LCDCommand(NOP); // nop(EPSON) }
void showRunningTime() { LCDGotoXY(10,0) ; if (runningHours > 1000) { LCDWriteInt(runningHours / 1000,1); LCDData(',') ; } LCDWriteInt(runningHours % 1000,1); }
void LCDShield::setPixel(int color, unsigned char x, unsigned char y) { y = (COL_HEIGHT - 1) - y; x = (ROW_LENGTH - 1) - x; if (driver == EPSON) // if it's an epson { LCDCommand(PASET); // page start/end ram LCDData(x); LCDData(ENDPAGE); LCDCommand(CASET); // column start/end ram LCDData(y); LCDData(ENDCOL); LCDCommand(RAMWR); // write LCDData((color>>4)&0x00FF); LCDData(((color&0x0F)<<4)|(color>>8)); LCDData(color&0x0FF); }
void showDate() { int d = (day-1) * 3 ; LCDWriteInt(date,2); LCDData('/') ; LCDWriteInt(month,2); LCDData('/') ; LCDData('2') ; LCDData('0') ; LCDWriteInt(year,2); LCDData(32) ; LCDData(32) ; LCDData(daysOfTheWeek[d++]) ; LCDData(daysOfTheWeek[d++]) ; LCDData(daysOfTheWeek[d]) ; }
void LCDSmartWrite(int x,int y,char *str) { int j=0; while(str[j]) { if(x>15) { x=0; y++; } LCDGotoXY(x,y); LCDData(str[j]); j++; x++; } }
void LCDShield::clear(int color) { if (driver) // if it's an Epson { LCDCommand(PASET); LCDData(0); LCDData(131); LCDCommand(CASET); LCDData(0); LCDData(131); LCDCommand(RAMWR); } else // otherwise it's a phillips { LCDCommand(PASETP); LCDData(0); LCDData(131); LCDCommand(CASETP); LCDData(0); LCDData(131); LCDCommand(RAMWRP); } for(unsigned int i=0; i < (131*131)/2; i++) { LCDData((color>>4)&0x00FF); LCDData(((color&0x0F)<<4)|(color>>8)); LCDData(color&0x0FF); } x_offset = 0; y_offset = 0; }
void LCDWriteString(const char *msg) { /***************************************************************** This function Writes a given string to lcd at the current cursor location. Arguments: msg: a null terminated string to print *****************************************************************/ while(*msg!='\0') { LCDData(*msg); msg++; } }
void LCDInit(uint8_t style) { __delay_ms(30); //Set IO Ports LCD_DATA_TRIS&=(~(0x0F<<LCD_DATA_POS)); //Output LCD_E_TRIS=0; //Output LCD_RS_TRIS=0; //Output LCD_RW_TRIS=0; //Output LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));//Clear data port CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set 4-bit mode __delay_us(0.5); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 __delay_us(1); CLEAR_E(); __delay_us(1); //Wait for LCD to execute the Functionset Command LCDBusyLoop(); //[B] Forgot this delay //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001100|style); //Display On /* Custom Char */ LCDCmd(0b01000000); uint8_t __i; for(__i=0;__i<sizeof(__cgram);__i++) LCDData(__cgram[__i]); }
writePixel(int x, int y) { int q; if (y >= 0 && y <= 7) { gotoXY(x,0); q = y - 0; } if (y > 7 && y <= 15) { gotoXY(x,1); q = y - 8; } if (y > 15 && y <= 23) { gotoXY(x,2); q = y - 16; } if (y > 23 && y <= 31) { gotoXY(x,3); q = y - 24; } if (y > 31 && y <= 39) { gotoXY(x,4); q = y - 32; } if (y > 39 && y <= 47) { gotoXY(x,5); q = y - 40; } LCDData(1 << q); }
//Usage: LCDInit(); //Inputs: None //Outputs: None //Description: Initializes the LCD regardless of if the controlller is an EPSON or PHILLIPS. void LCDInit(void) { delay_ms(200); cbi(LCD_PORT, SCK);//output_low (SPI_CLK);//output_low (SPI_DO); cbi(LCD_PORT, DIO); delay_us(10); sbi(LCD_PORT, CS); //output_high (LCD_CS); delay_us(10); cbi(LCD_PORT, LCD_RES); //output_low (LCD_RESET); delay_ms(200); sbi(LCD_PORT, LCD_RES); //output_high (LCD_RESET); delay_ms(200); sbi(LCD_PORT, SCK); sbi(LCD_PORT, DIO); delay_us(10); LCDCommand(DISCTL); // display control(EPSON) LCDData(0x0C); // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default) LCDData(0x20); //LCDData(0x02); LCDData(0x00); LCDData(0x01); LCDCommand(COMSCN); // common scanning direction(EPSON) LCDData(0x01); LCDCommand(OSCON); // internal oscialltor ON(EPSON) LCDCommand(SLPOUT); // sleep out(EPSON) LCDCommand(SLEEPOUT); //sleep out(PHILLIPS) LCDCommand(PWRCTR); // power ctrl(EPSON) LCDData(0x0F); //everything on, no external reference resistors LCDCommand(BSTRON); //Booset On(PHILLIPS) LCDCommand(DISINV); // invert display mode(EPSON) LCDCommand(INVON); // invert display mode(PHILLIPS) LCDCommand(DATCTL); // data control(EPSON) LCDData(0x03); //correct for normal sin7 LCDData(0x00); // normal RGB arrangement //LCDData(0x01); // 8-bit Grayscale LCDData(0x02); // 16-bit Grayscale Type A LCDCommand(MADCTL); //Memory Access Control(PHILLIPS) LCDData(0xC8); LCDCommand(COLMOD); //Set Color Mode(PHILLIPS) LCDData(0x02); LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness(EPSON) //LCDData(0x18); // volume (contrast) setting - fine tuning, original LCDData(0x24); // volume (contrast) setting - fine tuning, original LCDData(0x03); // internal resistor ratio - coarse adjustment LCDCommand(SETCON); //Set Contrast(PHILLIPS) LCDData(0x30); LCDCommand(NOP); // nop(EPSON) LCDCommand(NOPP); // nop(PHILLIPS) delay_ms(200); LCDCommand(DISON); // display on(EPSON) LCDCommand(DISPON); // display on(PHILLIPS) }
//normal write function breaks when drawing y lines (bug) writeY(int x, int y) { int q; int a = 0; if (y >= 0 && y <= 7) { gotoXY(x,0); q = y - 0; } if (y > 7 && y <= 15) { gotoXY(x,1); q = y - 8; } if (y > 15 && y <= 23) { gotoXY(x,2); q = y - 16; } if (y > 23 && y <= 31) { gotoXY(x,3); q = y - 24; } if (y > 31 && y <= 39) { gotoXY(x,4); q = y - 32; } if (y > 39 && y <= 47) { gotoXY(x,5); q = y - 40; } if (q == 0) LCDData(0xFF); if (q == 1) LCDData(0xFF); if (q == 2) LCDData(0xFF); if (q == 3) LCDData(0xFF); if (q == 4) LCDData(0xFF); if (q == 5) LCDData(0xFF); if (q == 6) LCDData(0xFF); if (q == 7) LCDData(0xFF); }
uint8_t Measure(void) { uint8_t low1,low2,low3; uint8_t high1,high2,high3; uint8_t lows,highs; uint8_t result; uint8_t delta1,delta2; result=RES_NONE; low1=low2=low3=0; high1=high2=high3=0; for (uint8_t i=1; i<7; i++) { CLRWDT(); SetMode(i); if (adc1<10) low1++; if (adc2<10) low2++; if (adc3<10) low3++; if (adc1>245) high1++; if (adc2>245) high2++; if (adc3>245) high3++; } CLRWDT(); lows=low1+low2+low3; highs=high1+high2+high3; if ((lows==6) && (highs==6)) { // NFET Signature result=RES_NCH; // Handle this in the most simplistic way according to the measurements // of a 2N7000 NFET. This is probably not correct and will possibly not work // in all cases. if (low1==1) { if (low2==2) result+=RES_GDS; if (low2==3) result+=RES_DGS; } if (low1==2) { if (low2==1) result+=RES_SDG; if (low2==3) result+=RES_SGD; } if (low1==3) { if (low2==1) result+=RES_DSG; if (low2==2) result+=RES_GSD; } } if ((lows==5) && (highs==4)) { // NPN Signature result=RES_NPN; if (low1==3) { delta1=SetAll(ILH, HII); // Test BEC delta2=SetAll(IHL, HII); // Test BCE if (delta1<delta2) { result+=RES_BEC; } else { result+=RES_BCE; } } if (low2==3) { delta1=SetAll(LIH, IHI); // Test EBC delta2=SetAll(HIL, IHI); // Test CBE if (delta1<delta2) { result+=RES_EBC; } else { result+=RES_CBE; } } if (low3==3) { delta1=SetAll(LHI, IIH); // Test ECB delta2=SetAll(HLI, IIH); // Test CEB if (delta1<delta2) { result+=RES_ECB; } else { result+=RES_CEB; } } } //MPSA92 PNP 1=E 2=B 3=C if ((lows==4) && (highs==5)) { // PNP Signature result=RES_PNP; if (high1==3) { delta1=SetAll(ILH, LII); // Test BEC delta2=SetAll(IHL, LII); // Test BCE if (delta1>delta2) { result+=RES_BEC; } else { result+=RES_BCE; } } if (high2==3) { delta1=SetAll(LIH, ILI); // Test EBC delta2=SetAll(HIL, ILI); // Test CBE if (delta1>delta2) { result+=RES_EBC; } else { result+=RES_CBE; } } if (high3==3) { delta1=SetAll(LHI, IIL); // Test ECB delta2=SetAll(HLI, IIL); // Test CEB if (delta1>delta2) { result+=RES_ECB; } else { result+=RES_CEB; } } } #ifdef _1LCD LCDCommand(0x01); // Clear if (result>=100 && result<=199) { LCDData('N'); LCDData('P'); LCDHexAt(delta1,3); LCDHexAt(delta2,6); LCDCommand(0xD0); LCDHexAt(0xB0+base,8); LCDHexAt(0xE0+emitter,11); LCDHexAt(0xC0+collector,14); } if (result>=200) { LCDData('P'); LCDData('N'); LCDHexAt(delta1,3); LCDHexAt(delta2,6); LCDCommand(0xD0); LCDHexAt(0xB0+base,8); LCDHexAt(0xE0+emitter,11); LCDHexAt(0xC0+collector,14); } #endif return result; }
void LCDShield::init(int type, bool colorSwap) { driver = type; // Initialize the control pins, and reset display: cbi(LCD_PORT_SCK, SCK_PIN); // CLK = LOW cbi(LCD_PORT_DIO, DIO); // DIO = LOW delayMicroseconds(10); // 10us delay sbi(LCD_PORT_CS, CS); // CS = HIGH delayMicroseconds(10); // 10uS Delay cbi(LCD_PORT_RES, LCD_RES); // RESET = LOW delay(200); // 200ms delay sbi(LCD_PORT_RES, LCD_RES); // RESET = HIGH delay(200); // 200ms delay sbi(LCD_PORT_SCK, SCK_PIN); // SCK_PIN = HIGH sbi(LCD_PORT_DIO, DIO); // DIO = HIGH delayMicroseconds(10); // 10us delay if (driver == EPSON) { LCDCommand(DISCTL); // Display control (0xCA) LCDData(0x0C); // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default) LCDData(0x20); // nlines/4 - 1 = 132/4 - 1 = 32 duty LCDData(0x00); // No inversely highlighted lines LCDCommand(COMSCN); // common scanning direction (0xBB) LCDData(0x01); // 1->68, 132<-69 scan direction LCDCommand(OSCON); // internal oscialltor ON (0xD1) LCDCommand(SLPOUT); // sleep out (0x94) LCDCommand(PWRCTR); // power ctrl (0x20) LCDData(0x0F); // everything on, no external reference resistors LCDCommand(DISINV); // invert display mode (0xA7) LCDCommand(DATCTL); // data control (0xBC) LCDData(0x03); // Inverse page address, reverse rotation column address, column scan-direction !!! try 0x01 LCDData(0x00); // normal RGB arrangement LCDData(0x02); // 16-bit Grayscale Type A (12-bit color) LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness (0x81) LCDData(32); // volume (contrast) setting - fine tuning, original (0-63) LCDData(3); // internal resistor ratio - coarse adjustment (0-7) LCDCommand(NOP); // nop (0x25) delay(100); LCDCommand(DISON); // display on (0xAF) } else if (driver == PHILIPS) { LCDCommand(SLEEPOUT); // Sleep Out (0x11) LCDCommand(BSTRON); // Booster voltage on (0x03) LCDCommand(DISPON); // Display on (0x29) //LCDCommand(INVON); // Inversion on (0x20) // 12-bit color pixel format: LCDCommand(COLMOD); // Color interface format (0x3A) LCDData(0x03); // 0b011 is 12-bit/pixel mode LCDCommand(MADCTL); // Memory Access Control(PHILLIPS) if (colorSwap) LCDData(0x08); else LCDData(0x00); LCDCommand(SETCON); // Set Contrast(PHILLIPS) LCDData(0x30); LCDCommand(NOPP); // nop(PHILLIPS) } }
void LCDBitmap(char my_array[]){ for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) LCDData(my_array[index]); }
void ColorLCDShield::init(int type) { driver = type; delay(200); cbi(LCD_PORT_SCK, SCK); //CLK = LOW cbi(LCD_PORT_DIO, DIO); //DIO = LOW delayMicroseconds(10); sbi(LCD_PORT_CS, CS); //CS = HIGH delayMicroseconds(10); cbi(LCD_PORT_RES, LCD_RES); //RESET = LOW delay(200); sbi(LCD_PORT_RES, LCD_RES); //RESET = HIGH delay(200); sbi(LCD_PORT_SCK, SCK); // SCK = HIGH sbi(LCD_PORT_DIO, DIO); // DIO = HIGH delayMicroseconds(10); LCDCommand(DISCTL); // display control(EPSON) LCDData(0x0C); // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default) LCDData(0x20); LCDData(0x00); LCDData(0x01); LCDCommand(COMSCN); // common scanning direction(EPSON) LCDData(0x01); LCDCommand(OSCON); // internal oscialltor ON(EPSON) LCDCommand(SLPOUT); // sleep out(EPSON) LCDCommand(SLEEPOUT); //sleep out(PHILLIPS) LCDCommand(PWRCTR); // power ctrl(EPSON) LCDData(0x0F); //everything on, no external reference resistors LCDCommand(BSTRON); //Booset On(PHILLIPS) LCDCommand(DISINV); // invert display mode(EPSON) LCDCommand(DATCTL); // data control(EPSON) LCDData(0x03); // correct for normal sin7 LCDData(0x00); // normal RGB arrangement LCDData(0x02); // 16-bit Grayscale Type A LCDCommand(COLMOD); // Set Color Mode(PHILLIPS) LCDData(0x03); LCDCommand(MADCTL); // Memory Access Control(PHILLIPS) LCDData(0xC8); LCDCommand(VOLCTR); // electronic volume, this is the contrast/brightness(EPSON) LCDData(0x24); // volume (contrast) setting - fine tuning, original LCDData(0x03); // internal resistor ratio - coarse adjustment LCDCommand(SETCON); // Set Contrast(PHILLIPS) LCDData(0x30); LCDCommand(NOP); // nop(EPSON) LCDCommand(NOPP); // nop(PHILLIPS) delayMicroseconds(200); LCDCommand(DISON); // display on(EPSON) LCDCommand(DISPON); // display on(PHILLIPS) }
void LCDClear(void) { for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++) LCDData(0x00); gotoXY(0, 0); }
int main(){ char **a; char **userNo; char **textContent; int textContentCounter = 0; int userNoCounter; DDRB = 0xFF; DDRD = 0b11111100; DDRC = 0xFF; DDRA = 0x00; PORTA = 0x00; initLCD(); USART_Init(78); sei(); /************************* display Init message ********************/ LCDClear(); LCDPrint ("uC working"); _delay_ms(1000); /*******************************************************************/ /****************************** GSM INIT ***************************/ okComplete = 0; sendATCommand("at"); while (okComplete == 0); if (okComplete == 1) { /************** GSM initilization success ******************/ LCDClear(); LCDPrintLines ("GSM init.:", "successful"); /***********************************************************/ /****** Check for EEPROM value and reset it ****************/ /***********************************************************/ }else { /************ GSM unsuccessful in initilization *************/ LCDClear(); LCDPrintLines ("GSM init.:", "failure"); _delay_ms(1000); LCDClear(); LCDPrint ("System Halting..."); while (1); /************************************************************/ } _delay_ms(1000); okComplete = 0; sendATCommand("at+cmgda=\"DEL ALL\""); while (okComplete == 0); if (okComplete == 1){ LCDPrintLines ("message Delete", "successful"); } else if (okComplete == 2) { LCDPrintLines ("can't del. msg.", "system halting..."); while (1); } _delay_ms(1000); okComplete = 1; /*******************************************************************/ whatIsGoingOn = NOTHING; bufferCount = 0; while (1){ if (okComplete == 1){ //OK received LCDClear(); if (whatIsGoingOn == NOTHING){ LCDPrintLines("Vending Machine", "Code: vm001"); } else if (whatIsGoingOn == MESSAGE_SEND_SUCCESSFULLY){ LCDPrintLines("Product Dropped", "Thank You"); } else if (whatIsGoingOn == ERRORV){ LCDPrintLines ("Last Message:", "vmCode invalid"); } else if (whatIsGoingOn == ERRORP){ LCDPrintLines ("Last Message:", "itemCode invalid"); } else if (whatIsGoingOn == ERRORR){ LCDPrintLines ("Last Message:", "5 Retries Error"); } else if (whatIsGoingOn == ERRORO){ LCDPrintLines ("Last Message:", "Overfall"); } else if (whatIsGoingOn == ERRORA){ LCDPrintLines ("Last Message:", "unavail. product"); } else if (whatIsGoingOn == ERRORPA){ LCDPrintLines ("Last Message:", "und. pinCode len"); } _delay_ms(1000); if (whatIsGoingOn != NOTHING){ whatIsGoingOn = NOTHING; okComplete = 1; } else { okComplete = 0; } } else if (okComplete == 2){ //ERROR Received LCDClear(); LCDPrint ("Error Received"); _delay_ms(1000); okComplete = 1; }else if (msgReceived == 1){ //=CMTI Received LCDClear(); LCDPrint ("msg rec @: "); if (msgNumber1 == 255){ LCDData ((char)msgNumber); } else { LCDData ((char)msgNumber); LCDData ((char)msgNumber1); } /******** read message and process on it **************/ //@1 set EEPROM //@1 (set EEPROM) complete okComplete = 0; /************** try 5 times to read SMS ***************/ char repeatCounter = 2; while (repeatCounter <= 5){ if (msgNumber1 == 255){ sendATCommand1("at+cmgr=", msgNumber); } else { sendATCommand2("at+cmgr=", msgNumber, msgNumber1); } while ((okComplete == 0)){ _delay_ms(200); } repeatCounter ++; if (okComplete == 1 || repeatCounter > 5){ break; } else { okComplete = 0; } } /******************************************************/ if (okComplete == 1){ /*********** AT+CMGR value received in buffer *********/ /*********** check for user number ********************/ if (authCheck){ userNo = split((char *) buffer, "\"", &userNoCounter); if (equals(userNo[3], AUTH_PHONENO) == 0){ freeSplitedString(userNo, userNoCounter); sendMessage1 (phoneNo, "Unknown number detected: ", userNo[3], 2); msgReceived = 0; msgNumber = -1; msgNumber1 = -1; continue; } freeSplitedString(userNo, userNoCounter); } /******************************************************/ /********** Check for message format ******************/ //@1 Spliting message char *tempA2Lower; a = split((char*) buffer, checkPattern, (int *)&counter); tempA2Lower = toLower(a[2]); free(a[2]); a[2] = tempA2Lower; textContent = split (a[2], " ", &textContentCounter); pinCode = textContent[0]; vmCode = textContent[1]; productCode = textContent[2]; //@1 Complete //@2 Check for 6 digit pinCode if (length(pinCode) == 6){ //@3 check for vmMachine code if (equals(vmCode, "vm001") == 1){ //@4 check for itemcode char *subSubString; subSubString = subString(productCode, 0, 1); if (equals(subSubString, "a")){ char *subSubString2; //@5 check for productValue int productValue; subSubString2 = subString(productCode, 1, 2); productValue = toInteger(subSubString2); if (productValue > 6 || productValue < 1){ /**** unavailable product ***********/ sendMessage1 (phoneNo, pinCode, "unavailable product", 2); LCDPrintLines("Error: ", "unavailable product"); whatIsGoingOn = ERRORA; /************************************/ } else { /******** Every thing is correct drop the product *****/ //@6 drop the product and display in LCD PORTC = (1 << (5 - (productValue - 1))); LCDPrintLines("Dropping", "Product: "); LCDPrint(subSubString2); //@6 (drop the product and display in LCD) complete //@7 start motor and count for 2 sec unsigned int fallCounter = 0; while ((!(bit_is_set(PINA, PA6))) && (!(bit_is_set(PINA, PA7)))) { /******* find out time take here *******/ _delay_ms(1); if (fallCounter > 2000){ break; } fallCounter++; /****************************************/ } //@8 stop the motor and check for time PORTC = 0x00; if (fallCounter >= 2000) { /*********** overFall error **************/ sendMessage1 (phoneNo, pinCode, "Overfall error", 2); LCDPrintLines("Error: ", "Overfall"); whatIsGoingOn = ERRORO; /*****************************************/ } else { /*********** success **************/ sendMessage (phoneNo, pinCode, 1); LCDPrintLines("Drop: ", "successful"); whatIsGoingOn = MESSAGE_SEND_SUCCESSFULLY; /*****************************************/ } //@7 () Complete /******************************************************/ } free (subSubString2); //@5 (Product value check) complete } else { /****** invalid vmCode *******/ sendMessage1 (phoneNo, pinCode, "productCode invalid", 2); LCDPrintLines("Error: ", "productCode invalid"); whatIsGoingOn = ERRORP; /*****************************/ } free (subSubString); //@4 (check for itemcode) complete } else { /****** invalid vmCode *******/ sendMessage1 (phoneNo, pinCode, "vmCode invalid", 2); LCDPrintLines("Error: ", "vmCode invalid"); whatIsGoingOn = ERRORV; /*****************************/ } //@3 (check for vmMachine code) completed } else { /******* invalid pinCode *******/ sendMessage1 (phoneNo, pinCode, "pinCode invalid", 2); LCDPrintLines("Error: und.", "pinCode length"); whatIsGoingOn = ERRORPA; /*******************************/ } //@2 (check for 6 digit pinCode) complete freeSplitedString (a, counter); freeSplitedString (textContent, textContentCounter); /******************************************************/ /******************************************************/ } else if (okComplete == 2){ /**************** error reading sms *******************/ sendMessage (phoneNo, "couldn't read message from GSM modem", 2); LCDPrintLines("Err Reading SMS", "5 Retries Error"); whatIsGoingOn = ERRORR; /******************************************************/ } /*********** delete the message **************/ if (msgNumber1 == 255) { sendATCommand1("at+cmgd=", msgNumber); } else { sendATCommand2("at+cmgd=", msgNumber, msgNumber1); } /*********************************************/ //@2 reset EEPROM //@2 (reset EEPROM) complete _delay_ms(1000); msgNumber = -1; msgNumber1 = -1; msgReceived = 0; } else if (ringReceived == 1){ //RING received LCDClear(); LCDPrintLines("Message Received:","dummy message"); _delay_ms(200); /******** read message and process on it **************/ //@1 set EEPROM //@1 (set EEPROM) complete okComplete = 1; strCpy((char*)newBuffer, (char*)buffer); if (okComplete == 1){ /*********** AT+CMGR value received in buffer *********/ /*********** check for user number ********************/ if (authCheck){ userNo = split((char *) buffer, "\"", &userNoCounter); if (equals(userNo[3], AUTH_PHONENO) == 0){ freeSplitedString(userNo, userNoCounter); sendMessage1 (phoneNo, "Unknown number detected: ", userNo[3], 2); msgReceived = 0; msgNumber = -1; msgNumber1 = -1; continue; } freeSplitedString(userNo, userNoCounter); } /******************************************************/ /********** Check for message format ******************/ //@1 Spliting message char *tempA2Lower; a = split((char*) buffer, checkPattern, (int *)&counter); tempA2Lower = toLower(a[2]); free(a[2]); a[2] = tempA2Lower; textContent = split (a[2], " ", &textContentCounter); pinCode = textContent[0]; vmCode = textContent[1]; productCode = textContent[2]; //@1 Complete //@2 Check for 6 digit pinCode if (length(pinCode) == 6){ //@3 check for vmMachine code if (equals(vmCode, "vm001") == 1){ //@4 check for itemcode char *subSubString; subSubString = subString(productCode, 0, 1); if (equals(subSubString, "a")){ char *subSubString2; //@5 check for productValue int productValue; subSubString2 = subString(productCode, 1, 2); productValue = toInteger(subSubString2); if (productValue > 6 || productValue < 1){ /**** unavailable product ***********/ LCDPrintLines("Error: ", "unavailable product"); whatIsGoingOn = ERRORA; /************************************/ } else { /******** Every thing is correct drop the product *****/ //@6 drop the product and display in LCD PORTC = (1 << (5 - (productValue - 1))); LCDPrintLines("Dropping", "Product: "); LCDPrint(subSubString2); //@6 (drop the product and display in LCD) complete //@7 start motor and count for 2 sec unsigned int fallCounter = 0; while ((!(bit_is_set(PINA, PA6))) && (!(bit_is_set(PINA, PA7)))) { /******* find out time take here *******/ _delay_ms(1); if (fallCounter > 2000){ break; } fallCounter++; /****************************************/ } //@8 stop the motor and check for time PORTC = 0x00; if (fallCounter >= 2000) { /*********** overFall error **************/ LCDPrintLines("Error: ", "Overfall"); whatIsGoingOn = ERRORO; /*****************************************/ } else { /*********** success **************/ LCDPrint("Drop success"); whatIsGoingOn = MESSAGE_SEND_SUCCESSFULLY; /*****************************************/ } //@7 () Complete /******************************************************/ } free (subSubString2); //@5 (Product value check) complete } else { /****** invalid vmCode *******/ LCDPrintLines("Error: ", "productCode invalid"); whatIsGoingOn = ERRORP; /*****************************/ } free (subSubString); //@4 (check for itemcode) complete } else { /****** invalid vmCode *******/ LCDPrintLines("Error: ", "vmCode invalid"); whatIsGoingOn = ERRORV; /*****************************/ } //@3 (check for vmMachine code) completed } else { /******* invalid pinCode *******/ LCDPrintLines("Error: und.", "pinCode length"); whatIsGoingOn = ERRORPA; /*******************************/ } //@2 (check for 6 digit pinCode) complete freeSplitedString (a, counter); freeSplitedString (textContent, textContentCounter); /******************************************************/ /******************************************************/ } else if (okComplete == 2){ /**************** error reading sms *******************/ LCDPrintLines("Err Reading SMS", "5 Retries Error"); whatIsGoingOn = ERRORR; /******************************************************/ } //@2 reset EEPROM //@2 (reset EEPROM) complete _delay_ms(1000); msgNumber = -1; msgNumber1 = -1; msgReceived = 0; /***********************************************************************/ ringReceived = 0; } } return 0; }