Arduino wire code and Microchip C18 for I2C

This is my first post here at Arduino. I see many, many good products interfaced with the wire language, I believe that is what it is called

But I just spent the last half year learning Microchip's C18 and I want to avoid if possible learning another language even if it is not a difficult language to learn. Also I would not be able to marry another language into C18 where I now have over 500 lines of code written. The compiler would reject it. I would like to purchase various Arduino parts for my project, currently in need for a 20X4 I2C alphanumeric display. Yes, I understand that I2C is a well described interface however from the code samples I see, they are all in wire format.

Are Arduino displays along with robotic product's Hex code commands available? That would make interfacing with C much easier and save me from having to learn another language. I really want to stick with C.

Thanks--

Foggy

There are several levels of confusion here - I'm not quite sure where to start.

The whole Arduino system is built around Atmel microcontrollers and the 'C' programming language. The Arduino hardware essentially consists of an Atmel microcontroller along with a power supply and some supporting chips. The Arduino software is essentially 'C' with a lot of the dirty work done behind the scenes.

Also I would not be able to marry another language into C18 where I now have over 500 lines of code written.

If you have well commented assembly language code it is usually not particularly difficult to rewrite it for another processor. If you have well commented 'C' code the job should almost be trivial. Finding well commented code, especially well commented 'C' code is another matter.

my project, currently in need for a 20X4 I2C alphanumeric display

A 20X4 I2C alphanumeric display that works with an Arduino will work with any other microcontroller as well and vice versa. The I2C interface that I am currently using between my Arduino hardware and my LCD modules is a Microchip device, the MCP23017.

Are Arduino displays ... available?

There is no such thing as an Arduino display. That's like going to a service station looking for Ford gasoline.

Don

Well Don, your reply was informative. But what I expected to see was greater detail as shown in the attached New Haven display specification rather than what I find on EBay that advertises "Arduino Displays." I realize that any manufacturer of displays or other major components/subassemblies could not limit their market to only Arduino, they need volume sales. Below is a sample code I copied from Ebay( http://www.ebay.com/itm/Arduino-IIC-I2C-TWI-16x2-1602-Serial-Character-LCD-Module-Display-Yellow-Green-/170758201812?pt=LH_DefaultDomain_0&hash=item27c1fb61d4 )

I do have a New Haven display (I2C) that I had no problems implementing. But if those components/subassemblies that are advertised as Aduino limit their interface information, I will use other products that provide specifications I have knowledge of understanding. I am not familiar with Atmel's chips or their C compiler. My C knowledge comprises that of Microchip's C18 along with C programming found in "The C Programming Language" by Kernighan & Ritchie along with others such as Kochan's "Programming in C."

Thank you for your helpful reply!

Foggy

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
????lcd.init();
????lcd.backlight();
????lcd.setCursor(0, 0);
????lcd.print("www.b2cqshop.com");
????lcd.setCursor(0, 1);
????lcd.print("Voltage: ");
????lcd.setCursor(13, 1);
????lcd.print("V");
}
void loop()
{
????int val;
????float temp;
???? val=analogRead(0);
????temp=val/4.092;
????val=(int)temp;//
????lcd.setCursor(9, 1);
????lcd.print(0x30+val/100,BYTE);
????lcd.print(0x30+(val%100)/10,BYTE);
????lcd.print('.');
????lcd.print(0x30+val%10,BYTE);
????delay(100);
}

NHD-0420D3Z-NSW-BBW.pdf (318 KB)

Back again--

I thought it would be helpful to provide a couple of code segments from the program I am currently writing.

First is a function that delays writing until the slave has provided an ack. Next is a function that I use to convert integers to ASCII numbers with the added 0x03 needed to write to the display using C18.

Third is some of the display code.

Foggy

void test_ack()

{

if(SSPCON1bits.WCOL) //DDPBUF register, conditions not valid for transmission
SSPCON1bits.WCOL = 0; //<7>

if (PIR1bits.SSPIF=1) //<7> transmission complete flag
PIR1bits.SSPIF = 0; //

while(SSPCON2bits.ACKSTAT) //<6>acknowledge not received when ACKSTAT = 1
{

}

while(SSPSTATbits.BF) //<0> indicates SSPBUF is full
{
sspbuf = SSPBUF; // reading the buffer clears it
}

}

void segments(void)

void segments(void)

// below converts the digital number from above to individual integers
// look up table for ASCII numbers for Newhaven display

{

run_minutes=set_run_min; // ones
ones=run_minutes % 10;

run_minutes /= 10; // tens
tens = run_minutes % 10;

run_minutes /= 10; // hundreds
hundreds = run_minutes % 10;

seg_value[0] = 0b00110000; // 0
seg_value[1] = 0b00110001; // 1
seg_value[2] = 0b00110010; // 2
seg_value[3] = 0b00110011; // 3
seg_value[4] = 0b00110100; // 4
seg_value[5] = 0b00110101; // 5
seg_value[6] = 0b00110110; // 6
seg_value[7] = 0b00110111; // 7
seg_value[8] = 0b00111000; // 8
seg_value[9] = 0b00111001; // 9

p = seg_value[ones]; // p,q & r read the values from the array
q = seg_value[tens];
r = seg_value[hundreds];

StartI2C();

WriteI2C(0x50); //slave address
test_ack();
WriteI2C(0xFE); // clears screen
test_ack();
WriteI2C(0x51); // command
StopI2C();
Delay10TCYx(1);

}

segments(); //function call to get numbers
// Delay10TCYx(1);
StartI2C();
// test_ack();
WriteI2C(0x50); //slave address
test_ack();
WriteI2C(0xFE); // these lines for contrast
test_ack();
WriteI2C(0x52); //
test_ack();
WriteI2C(0x20); //set to 20-21 for best appearance
test_ack();
WriteI2C(0xFE); // these lines for backlight brightness
test_ack();
WriteI2C(0x53);
test_ack();
WriteI2C(0x05); // set to 05
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x00); // cursor position
test_ack();
putsI2C(set_run);
test_ack();
WriteI2C( r);
test_ack();
WriteI2C(q);
test_ack();
WriteI2C(p);
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x14); // cursor position col 1, row 3
test_ack();
putsI2C(lower_pres1);
test_ack();
WriteI2C(0xFE); //cursor position
test_ack();
WriteI2C(0x45); //cursor position
test_ack();
WriteI2C(0x54); // cursor position col 1, row 4
test_ack();
putsI2C(lower_pres2);

StopI2C();
//Delay10TCYx(1);

}

The only thing that makes the Ebay device that you referred an 'Arduino' display is the fact that the person who wrote the advertisement chose to append the word 'Arduino' to the beginning of his description.

There are some breakout boards, called 'shields', that are specific to the Arduino. What makes them specific is that they have pins on them that will exactly match the oddly spaced sockets on the Arduino pc board. There is no reason why you could not use any of the devices on those shields with another microprocessor as long as you were willing to make the interconnections in some manner other than just plugging the shield into matching sockets.

The New Haven device that you refer to seems to be a standard character mode LCD with a pre-programmed microprocessor attached that reads the serial signals sent to it and issues the appropriate commands to the LCD controller. Most implementations use a daughterboard for the microprocessor but this one has the microprocessor right on the main LCD PC board. Either type can be used with any microprocessor or other device that emits the appropriate serial signal.

I don't know what the significance of your two code samples is.

Next is a function that I use to convert integers to ASCII numbers with the added 0x03 needed to write to the display using C18.

Are you sure it isn't 0x30. I don't do much 'C' programming but even I have heard of the itoa (Integer to Ascii) function.

Don

{Edit}: I just looked at your code. Why are you using a lookup table for something that can be done so easily. All you have to do is get the number, make sure it is within the proper range, and then 'or' it with 0x30.

The significance was to compare my well commented C source code to the gibberish code example found in the EBay display specification which was in my last post.

Your right on with your other comments. In my rush to get my reply out, it is 0x30 that must be added or or'd. I did not even think about or'ing. If you notice the array's name, itis segments. I originally was using 7 segment leds and had to code for them. I just changed the code from segments to what New Haven needed. I will make changes to implement your suggestion.

Foggy

Instead of:

    test_ack();
    WriteI2C(0xFE);      //cursor position
    test_ack();         
    WriteI2C(0x45);      //cursor position
    test_ack();   
    WriteI2C(0x54);      // cursor position col 1, row 4

How about something like this:

// cursor position
    test_ack();
    WriteI2C(0xFE);      // command prefix
    test_ack();         
    WriteI2C(0x45);      // 'Set cursor' command
    test_ack();   
    WriteI2C(0x54);      // Line 4, Column 1

Or this: (I'm not sure of the exact syntax but you should get the idea)

// cursor position
    test_ack();
    WriteI2C(prefix);      // command prefix
    test_ack();         
    WriteI2C(SetCursor);   // 'Set cursor' command
    test_ack();   
    WriteI2C(Line4);       // Line 4, Column 1

Of course you would have previously defined prefix, SetCursor, and Line4.
For Line 4 column 3 you would use something like: WriteI2C(Line4+2);

Don

First you must remember... or maybe I did not mention that I am self taught in C which I started learning last spring. Your method for comments is very good. Many of my code sections are highlight/comments in the same fashion. The only person who will have a need for my code of course is me. I am working on a home project for personal enrichment.

And of course--- neophyte's programming. I did not give thought to defining. I will remember to use that approach in the future.

Hey! From what I see in the forums so far, appears to be a good group of folks all trying to help each other.

Some of the things I have remaining to do is to interface an A/D converter (it resides on my 18F4550 processor) along with getting a system clock running to time events. Also I want to get into a small motor.... not sure if I will go with a set motor or just something that is geared down. The motor will be mechanically attached to and turn a small high pressure valve.

Getting late, thanks for sharing ideas!

Foggy