We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
https://github.com/ExploreEmbedded/Explore-Cortex-M3-LPC1768-DVB-14001/blob/master/Code/KeilExamples/00-libfiles/oled_i2c.c
oled library
main
main(){//init_OLED(); SystemInit(); i2c0Init();// OLED_Init(); OLED_Init(P0_19, P0_20); // OLED_SetFont(SmallFont); //OLED_SetFont(2);
while(1) { //OLED_SetFont(MediumNumbers); for(i=0;i<1000;i++) { OLED_PrintFloatNumber(i/3.0,3,50,0); OLED_Update();// delay_ms(1000); } }}
please help i want to print a dtring on oled
#include <lpc17xx.h> #include <stdint.h> #include "i2c_driver.h" //#include "gpio.h" //#include "stdutils.h" //#include "oled.h" #include <string.h> #define SSD1306_ADDRESS 0x3C #define C_OledLastLine_U8 0x07u #define SSD1306_COMMAND 0x00 #define SSD1306_DATA 0xC0 #define SSD1306_DATA_CONTINUE 0x40 #define SSD1306_SET_CONTRAST_CONTROL 0x81 #define SSD1306_DISPLAY_ALL_ON_RESUME 0xA4 #define SSD1306_DISPLAY_ALL_ON 0xA5 #define SSD1306_NORMAL_DISPLAY 0xA6 #define SSD1306_INVERT_DISPLAY 0xA7 #define SSD1306_DISPLAY_OFF 0xAE #define SSD1306_DISPLAY_ON 0xAF #define SSD1306_NOP 0xE3 #define SSD1306_HORIZONTAL_SCROLL_RIGHT 0x26 #define SSD1306_HORIZONTAL_SCROLL_LEFT 0x27 #define SSD1306_HORIZONTAL_SCROLL_VERTICAL_AND_RIGHT 0x29 #define SSD1306_HORIZONTAL_SCROLL_VERTICAL_AND_LEFT 0x2A #define SSD1306_DEACTIVATE_SCROLL 0x2E #define SSD1306_ACTIVATE_SCROLL 0x2F #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 #define SSD1306_SET_LOWER_COLUMN 0x00 #define SSD1306_SET_HIGHER_COLUMN 0x10 #define SSD1306_MEMORY_ADDR_MODE 0x20 #define SSD1306_SET_COLUMN_ADDR 0x21 #define SSD1306_SET_PAGE_ADDR 0x22 #define SSD1306_SET_START_LINE 0x40 #define SSD1306_SET_SEGMENT_REMAP 0xA0 #define SSD1306_SET_MULTIPLEX_RATIO 0xA8 #define SSD1306_COM_SCAN_DIR_INC 0xC0 #define SSD1306_COM_SCAN_DIR_DEC 0xC8 #define SSD1306_SET_DISPLAY_OFFSET 0xD3 #define SSD1306_SET_COM_PINS 0xDA #define SSD1306_CHARGE_PUMP 0x8D #define SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO 0xD5 #define SSD1306_SET_PRECHARGE_PERIOD 0xD9 #define SSD1306_SET_VCOM_DESELECT 0xDB uint8_t OledLineNum,OledCursorPos; void oledSendCommand(uint8_t cmd) { i2c_start(); i2c_write(0x3C); i2c_write(SSD1306_COMMAND); i2c_write(cmd); i2c_stop(); } void oledSendStart(uint8_t address) { i2c_start(); i2c_write(0x3c); i2c_write(address); i2c_stop(); } void oledSendByte(uint8_t ch) { char i; i2c_start(); i2c_write(SSD1306_ADDRESS); i2c_write(ch); i2c_stop(); } void OLED_Clear() { int i; oledSendCommand(SSD1306_SET_COLUMN_ADDR); oledSendCommand(0); oledSendCommand(127); oledSendCommand(SSD1306_SET_PAGE_ADDR); oledSendCommand(0); oledSendCommand(7); oledSendStart(SSD1306_ADDRESS<<1); oledSendByte(SSD1306_DATA_CONTINUE); for (i=0; i<1024; i++) // Write Zeros to clear the display { oledSendByte(0); } oledSendCommand(SSD1306_SET_COLUMN_ADDR); oledSendCommand(0); oledSendCommand(127); oledSendCommand(SSD1306_SET_PAGE_ADDR); oledSendCommand(0); oledSendCommand(7); oledSendStart(SSD1306_ADDRESS<<1); oledSendByte(SSD1306_DATA_CONTINUE); } void OLED_Init(void) { oledSendCommand(SSD1306_DISPLAY_OFF); oledSendCommand(SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO); oledSendCommand(0x80); oledSendCommand(SSD1306_SET_MULTIPLEX_RATIO); oledSendCommand(0x3F); oledSendCommand(SSD1306_SET_DISPLAY_OFFSET); oledSendCommand(0x0); oledSendCommand(SSD1306_SET_START_LINE | 0x0); oledSendCommand(SSD1306_CHARGE_PUMP); oledSendCommand(0x14); oledSendCommand(SSD1306_MEMORY_ADDR_MODE); oledSendCommand(0x00); oledSendCommand(SSD1306_SET_SEGMENT_REMAP | 0x1); oledSendCommand(SSD1306_COM_SCAN_DIR_DEC); oledSendCommand(SSD1306_SET_COM_PINS); oledSendCommand(0x12); oledSendCommand(SSD1306_SET_CONTRAST_CONTROL); oledSendCommand(0xCF); oledSendCommand(SSD1306_SET_PRECHARGE_PERIOD); oledSendCommand(0xF1); oledSendCommand(SSD1306_SET_VCOM_DESELECT); oledSendCommand(0x40); oledSendCommand(SSD1306_DISPLAY_ALL_ON_RESUME); oledSendCommand(SSD1306_NORMAL_DISPLAY); oledSendCommand(SSD1306_DISPLAY_ON); OLED_Clear(); } void OLED_SetCursor(uint8_t lineNumber,uint8_t cursorPosition) { /* Move the Cursor to specified position only if it is in range */ if((lineNumber <= C_OledLastLine_U8) && (cursorPosition <= 127)) { OledLineNum=lineNumber; /* Save the specified line number */ OledCursorPos=cursorPosition; /* Save the specified cursor position */ oledSendCommand(SSD1306_SET_COLUMN_ADDR); oledSendCommand(cursorPosition); oledSendCommand(127); oledSendCommand(SSD1306_SET_PAGE_ADDR); oledSendCommand(lineNumber); oledSendCommand(7); oledSendStart(SSD1306_ADDRESS<<1); oledSendByte(SSD1306_DATA_CONTINUE); } } #if (Enable_OLED_GoToLine == 1) void OLED_GoToLine(uint8_t lineNumber) { if(lineNumber<8) { /* If the line number is within range then move it to specified line and keep track*/ OledLineNum = lineNumber; OLED_SetCursor(OledLineNum,0); } } #endif void OLED_GoToNextLine() { /*Increment the current line number. In case it exceeds the limit, rool it back to first line */ OledLineNum++; OledLineNum = OledLineNum&0x07; OLED_SetCursor(OledLineNum,0); /* Finally move it to next line */ } #if (Enable_OLED_DisplayLogo == 1) void OLED_DisplayLogo(char *ptr_Logo) { int i; OLED_SetCursor(0,0); oledSendStart(SSD1306_ADDRESS<<1); oledSendByte(SSD1306_DATA_CONTINUE); for ( i=0; i<1024; i++) // Send data { oledSendByte(ptr_Logo[i]); } } #endif #define FONT_SIZE 5 const OledFontTable[][FONT_SIZE]= { 0x00, 0x00, 0x00, 0x00, 0x00, // space 0x00, 0x00, 0x2f, 0x00, 0x00, // ! 0x00, 0x07, 0x00, 0x07, 0x00, // " 0x14, 0x7f, 0x14, 0x7f, 0x14, // # 0x24, 0x2a, 0x7f, 0x2a, 0x12, // $ 0x23, 0x13, 0x08, 0x64, 0x62, // % 0x36, 0x49, 0x55, 0x22, 0x50, // & 0x00, 0x05, 0x03, 0x00, 0x00, // ' 0x00, 0x1c, 0x22, 0x41, 0x00, // ( 0x00, 0x41, 0x22, 0x1c, 0x00, // ) 0x14, 0x08, 0x3E, 0x08, 0x14, // * 0x08, 0x08, 0x3E, 0x08, 0x08, // + 0x00, 0x00, 0xA0, 0x60, 0x00, // , 0x08, 0x08, 0x08, 0x08, 0x08, // - 0x00, 0x60, 0x60, 0x00, 0x00, // . 0x20, 0x10, 0x08, 0x04, 0x02, // / 0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 0x00, 0x42, 0x7F, 0x40, 0x00, // 1 0x42, 0x61, 0x51, 0x49, 0x46, // 2 0x21, 0x41, 0x45, 0x4B, 0x31, // 3 0x18, 0x14, 0x12, 0x7F, 0x10, // 4 0x27, 0x45, 0x45, 0x45, 0x39, // 5 0x3C, 0x4A, 0x49, 0x49, 0x30, // 6 0x01, 0x71, 0x09, 0x05, 0x03, // 7 0x36, 0x49, 0x49, 0x49, 0x36, // 8 0x06, 0x49, 0x49, 0x29, 0x1E, // 9 0x00, 0x36, 0x36, 0x00, 0x00, // : 0x00, 0x56, 0x36, 0x00, 0x00, // ; 0x08, 0x14, 0x22, 0x41, 0x00, // < 0x14, 0x14, 0x14, 0x14, 0x14, // = 0x00, 0x41, 0x22, 0x14, 0x08, // > 0x02, 0x01, 0x51, 0x09, 0x06, // ? 0x32, 0x49, 0x59, 0x51, 0x3E, // @ 0x7C, 0x12, 0x11, 0x12, 0x7C, // A 0x7F, 0x49, 0x49, 0x49, 0x36, // B 0x3E, 0x41, 0x41, 0x41, 0x22, // C 0x7F, 0x41, 0x41, 0x22, 0x1C, // D 0x7F, 0x49, 0x49, 0x49, 0x41, // E 0x7F, 0x09, 0x09, 0x09, 0x01, // F 0x3E, 0x41, 0x49, 0x49, 0x7A, // G 0x7F, 0x08, 0x08, 0x08, 0x7F, // H 0x00, 0x41, 0x7F, 0x41, 0x00, // I 0x20, 0x40, 0x41, 0x3F, 0x01, // J 0x7F, 0x08, 0x14, 0x22, 0x41, // K 0x7F, 0x40, 0x40, 0x40, 0x40, // L 0x7F, 0x02, 0x0C, 0x02, 0x7F, // M 0x7F, 0x04, 0x08, 0x10, 0x7F, // N 0x3E, 0x41, 0x41, 0x41, 0x3E, // O 0x7F, 0x09, 0x09, 0x09, 0x06, // P 0x3E, 0x41, 0x51, 0x21, 0x5E, // Q 0x7F, 0x09, 0x19, 0x29, 0x46, // R 0x46, 0x49, 0x49, 0x49, 0x31, // S 0x01, 0x01, 0x7F, 0x01, 0x01, // T 0x3F, 0x40, 0x40, 0x40, 0x3F, // U 0x1F, 0x20, 0x40, 0x20, 0x1F, // V 0x3F, 0x40, 0x38, 0x40, 0x3F, // W 0x63, 0x14, 0x08, 0x14, 0x63, // X 0x07, 0x08, 0x70, 0x08, 0x07, // Y 0x61, 0x51, 0x49, 0x45, 0x43, // Z 0x00, 0x7F, 0x41, 0x41, 0x00, // [ 0x55, 0xAA, 0x55, 0xAA, 0x55, // Backslash (Checker pattern) 0x00, 0x41, 0x41, 0x7F, 0x00, // ] 0x04, 0x02, 0x01, 0x02, 0x04, // ^ 0x40, 0x40, 0x40, 0x40, 0x40, // _ 0x00, 0x03, 0x05, 0x00, 0x00, // ` 0x20, 0x54, 0x54, 0x54, 0x78, // a 0x7F, 0x48, 0x44, 0x44, 0x38, // b 0x38, 0x44, 0x44, 0x44, 0x20, // c 0x38, 0x44, 0x44, 0x48, 0x7F, // d 0x38, 0x54, 0x54, 0x54, 0x18, // e 0x08, 0x7E, 0x09, 0x01, 0x02, // f 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g 0x7F, 0x08, 0x04, 0x04, 0x78, // h 0x00, 0x44, 0x7D, 0x40, 0x00, // i 0x40, 0x80, 0x84, 0x7D, 0x00, // j 0x7F, 0x10, 0x28, 0x44, 0x00, // k 0x00, 0x41, 0x7F, 0x40, 0x00, // l 0x7C, 0x04, 0x18, 0x04, 0x78, // m 0x7C, 0x08, 0x04, 0x04, 0x78, // n 0x38, 0x44, 0x44, 0x44, 0x38, // o 0xFC, 0x24, 0x24, 0x24, 0x18, // p 0x18, 0x24, 0x24, 0x18, 0xFC, // q 0x7C, 0x08, 0x04, 0x04, 0x08, // r 0x48, 0x54, 0x54, 0x54, 0x20, // s 0x04, 0x3F, 0x44, 0x40, 0x20, // t 0x3C, 0x40, 0x40, 0x20, 0x7C, // u 0x1C, 0x20, 0x40, 0x20, 0x1C, // v 0x3C, 0x40, 0x30, 0x40, 0x3C, // w 0x44, 0x28, 0x10, 0x28, 0x44, // x 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, // y 0x44, 0x64, 0x54, 0x4C, 0x44, // z 0x00, 0x10, 0x7C, 0x82, 0x00, // { 0x00, 0x00, 0xFF, 0x00, 0x00, // | 0x00, 0x82, 0x7C, 0x10, 0x00, // } 0x00, 0x06, 0x09, 0x09, 0x06 // ~ (Degrees) }; void OLED_DisplayChar(uint8_t ch) { uint8_t dat,i=0; if(((OledCursorPos+FONT_SIZE)>=128) || (ch=='\n')) { /* If the cursor has reached to end of line on page1 OR NewLine command is issued Then Move the cursor to next line */ OLED_GoToNextLine(); } if(ch!='\n') /* TODO */ { ch = ch-0x20; // As the lookup table starts from Space(0x20) while(1) { dat= OledFontTable[ch][i]; /* Get the data to be displayed for LookUptable*/ oledSendByte(dat); /* Display the data and keep track of cursor */ OledCursorPos++; i++; if(i==FONT_SIZE) /* Exit the loop if End of char is encountered */ { oledSendByte(0x00); /* Display the data and keep track of cursor */ OledCursorPos++; break; } } } } void OLED_DisplayString(uint8_t *ptr) { while(*ptr) OLED_DisplayChar(*ptr++); } main() { i2c0Init(); // i2c int // OLED_Init(); // oled init// OLED_SetCursor(2,0); OLED_DisplayString("Agam"); OLED_SetCursor(4,20); OLED_DisplayString("panday"); while(1) { //TODO:: Please write your application code } }
void i2c0Init(void) { LPC_SC->PCONP |= (1 << 19); // power clok to the i2c0 //LPC_PINCON->PINSEL1 &= ~((0x03<<22) | (0x03<<24)); // clearing the bits LPC_PINCON->PINSEL0 |= 0x0000000F ; // enable the scl,sdl 1 //my i2c intial// LPC_SC->PCLKSEL0 |= 0x00004000; // clock /2 LPC_I2C1->I2SCLH = 128; // LPC_I2C1->I2SCLL = 128; // //NVIC_EnableIRQ(I2C0_IRQn); } void i2c_start() { LPC_I2C1->I2CONCLR = 0x000000FF; // Clear all I2C settings LPC_I2C1->I2CONSET = (1<< I2EN); // Enable the I2C interface LPC_I2C1->I2CONSET = (1<< STA); // Start condition while(LPC_I2C1->I2STAT != 0x08); // wait until A START condition has been transmitted. } void i2c_stop(void) { unsigned int status; LPC_I2C1->I2CONCLR = (1<<STA); // START flag Clear bit. LPC_I2C1->I2CONCLR = (1<<SI); // I2C interrupt Clear bit. LPC_I2C1->I2CONCLR = (1<<AA); // ACK flag Clear bit. LPC_I2C1->I2CONSET = (1<<STO); // STOP flag. } void i2c_write(unsigned char data) { unsigned int status; LPC_I2C1->I2DAT = data; // This register holds contents of the 8 MSBs of the I2DAT shift register. LPC_I2C1->I2CONCLR = (1<<STA); LPC_I2C1->I2CONCLR = (1<<AA); // ACK flag Clear bit. LPC_I2C1->I2CONCLR = (1<<SI); // I2C interrupt Clear bit. //while(LPC_I2C0->I2STAT != 0x28); // Data byte in I2DAT has been transmitted; ACK has been received. while(!((status=LPC_I2C1->I2CONSET)& (1<<SI))); } unsigned char I2Cget(void) { unsigned char data; unsigned int status; LPC_I2C1->I2CONCLR = (1<<STA); LPC_I2C1->I2CONCLR = (1<<STO); LPC_I2C1->I2CONCLR = (1<<SI); LPC_I2C1->I2CONSET = (1<<AA); // send ack to continue further data transfer while(!((status=LPC_I2C1->I2CONSET)& (1<<SI))); //wait till interrupt flag becomes set data = LPC_I2C1->I2DAT ; return data; }
tank you for little guidance this is my code ,when i use simulation debug it is struck in system init()> clock section ,
when i comment all the functions except 12cinit(); iam sendind some dummy data to sdl line i can see in c.r.o .
please help me