Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help how to show single character from text in mikroc

Status
Not open for further replies.

polona1010

Member level 1
Member level 1
Joined
Apr 17, 2013
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,524
Hello

Can someone help me in Mikro C with lcd_out and text in array?

char code1[] = \\\"A1B2C3D4E5F6G7H8\\\"; - without this char \\ in this post this showup I cant remove that

When I print this code on LCD this is Ok:
Lcd_Out(1, 1, code1);

But when I want to show one character from code1 I get some bad bytes on LCD:
Lcd_Out(2, 1, code1[3]); - I think this will show 3 character from array but I get some bytes on lcd
Lcd_Out(2, 1, code1[1]); - I get nothing on LCD


Can someone help me to get one character from string in Mikro C 6 ?
 

To Display single character use:
Lcd_Chr function.
Eg:
PHP:
 Lcd_Chr(2, 1, code1[3]);
Lcd_Chr(2, 1, code1[1]);
 
Thank you very much sabin code works, and can you help me to show two characters on lcd at the same time, like in blocks of two char.

How to merge two char from this code A1B2C3D4E5F6G7H8 and write two char as one on lcd. A1 B2 C3 D4 E5...
 

PHP:
unsigned char i;
char msg[] ="A1B2C3D4E5F6G7H8";
Lcd_Cmd(_LCD_RETURN_HOME);

for(i=0;i<strlen(msg);i++){
Lcd_Chr_CP(msg[i]);
Lcd_Chr_CP(msg[++i]);
Lcd_Chr_CP(' ');
}

Modify the above code snippet and add to your program.
 
Sabin this works to, thanks a lot.

Can you help me for one more thing.

Defined code is :
char code1[] = \\\"A1B2C3D4E5F6G7H8\\\";

I need to write code in internal eeprom as following example :
A1 in 0x01, B2 in 0x02, C3 in 0x03,...

or on any other address in eeprom in serie.
 

Since A1 is two bytes you need to write it in two successive locations.
eg:
PHP:
EEPROM_Write(0x01,code1[0]); //store 'A'
EEPROM_Write(0x02,code1[1]); //Store '1'

You can use a loop to store all those values:
PHP:
int i;
char code1[] = "A1B2C3D4E5F6G7H8";
for(i=0;i<strlen(code1);i++){
EEPROM_Write(i,code1[i]); //store the value from code[i] to eeprom location starting from 0
Delay_ms(50);   //put delay because writing to eeprom takes  little time
}

To read the values:
PHP:
int i;
char code1[17] ;
code1[17]='\0';  //to make it string add a trailing '\0'
for(i=0;i<strlen(code1);i++){
code1[i] = EEPROM_Read(i);  //read value from address starting from 0
Delay_ms(50);   //put delay because writing to eeprom takes  little time
}
 
Last edited:
Sabin14 thank you very much you are helpful.

Can you help me in one more thing about usage of eeprom I2C 24C08 for example?

How to read and write data in 24C08. This code for example \"A1B2C3D4E5F6G7H8\".
 

Sabin14 thank you very much you are helpful.

Can you help me in one more thing about usage of eeprom I2C 24C08 for example?

How to read and write data in 24C08. This code for example \"A1B2C3D4E5F6G7H8\".


Hi Polona, here is one simple example provided by MikroElektronika :

Code:
/*
 * Project name:
     I2C_Simple (Simple test of I2C library routines)
 * Copyright:
     (c) Mikroelektronika, 2011.
 * Revision History:
     20110929:
       - initial release (FJ);
 * Description:
     This program demonstrates usage of the I2C library routines. It
     establishes I2C bus communication with 24C02 EEPROM chip, writes one byte
     of data on some location, then reads it and displays it on PORTB.
 * Test configuration:
     MCU:             PIC18F45K22
                      http://ww1.microchip.com/downloads/en/DeviceDoc/41412D.pdf
     Dev.Board:       EasyPIC7 - ac:Serial_EEPROM
                      http://www.mikroe.com/easypic/
     Oscillator:      HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
     Ext. Modules:    None.
     SW:              mikroC PRO for PIC
                      http://www.mikroe.com/mikroc/pic/
 * NOTES:
     - Turn on I2C switches SW4.7 and SW4.8. (board specific)
     - Turn off PORTC LEDs (SW3.3). (board specific)
     - Turn on PORTB LEDs (SW3.2). (board specific)
 */

void main(){
  ANSELB = 0;                // Configure PORTB pins as digital
  ANSELC = 0;                // Configure PORTC pins as digital
  
  TRISB = 0;                 // Configure PORTB as output
  LATB = 0;                  // Clear PORTB

  I2C1_Init(100000);         // initialize I2C communication
  I2C1_Start();              // issue I2C start signal
  I2C1_Wr(0xA2);             // send byte via I2C  (device address + W)
  I2C1_Wr(2);                // send byte (address of EEPROM location)
  I2C1_Wr(0xAA);             // send data (data to be written)
  I2C1_Stop();               // issue I2C stop signal

  Delay_100ms();

  I2C1_Start();              // issue I2C start signal
  I2C1_Wr(0xA2);             // send byte via I2C  (device address + W)
  I2C1_Wr(2);                // send byte (data address)
  I2C1_Repeated_Start();     // issue I2C signal repeated start
  I2C1_Wr(0xA3);             // send byte (device address + R)
  LATB = I2C1_Rd(0u);        // Read the data (NO acknowledge)
  I2C1_Stop();               // issue I2C stop signal
}


Dont forget to adjust correct port pins.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top