Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MCC18 Loops and such

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey all decided to try out MCC18 again and im having trouble compiling my code. When i remove the below from my code it compiles well so i assume it has to do with the below:

Code:
    char bl;      //Byte Loop
	for(bl=0;bl<8;bl++){

        if((cb & 0x80) != 0)
            SDA = 1;
        else
            SDA = 0;

    i2c_clock();
    cb=cb<<1;
    }

Can someone spot a potential problem?

EDIT FORGET THIS
Error: syntax error @:
Code:
char bl;      //Byte Loop

I added full code that i have so far.
 

Attachments

  • xee.c
    1.8 KB · Views: 133
Last edited:
You need to declare variables at the beginning of a block.

Try moving it up,
Code:
void i2c_start(unsigned char cb)
{
char bl;          //Byte Loop    [COLOR="Red"] <<<move to here[/COLOR]
    SDA_TRIS=0;   //SDA Output
    SCL=0;        //Clock Low
//Start
    SDA=1;        //SDA High
    SCL=1;        //Clock high
    d5();         //5us delay
    SDA=0;        //SDA Low
    d5();         //5us delay
    SCL=0;        //Clock Low

//Control Byte
    for(bl=0;bl<8;bl++){

        if((cb & 0x80) != 0)
            SDA = 1;
        else
            SDA = 0;

    i2c_clock();
    cb=cb<<1;
    }

Mike.
 
OMG that a crazy thing to do i didnt even know that lol. Thanks Works!!! (btw i knew you was going to reply to this) Since you was the last active one here lol
 
This is how I read 8 bits in my one wire routines,
Code:
unsigned char OwReadByte(){
unsigned char temp,i;
    temp=0;             //will hold result
    for(i=0;i<8;i++){   //get 8 bits
        temp=temp>>1;   //align bits
        if(OwReadBit()) //if read bit is 1
            temp.7=1;   //set bit 7 of temp
    }
    return temp;
}

Mike.
 
I forgot, that code is for Source Boost C compiler.

You can replace temp.7=1; with temp|=128;

Mike.
 
wow thanks. This is funny tho. I had to change your code to the below because it came in reverse :D but works 100% thanks again! I can now write & read External EEprom using I2C.

Code:
    for(i=0;i<8;i++){  
        temp=temp<<1;   

        if(SDA_PORT) 
            temp|=1;

        i2c_clock();
    }
 
Here are some pics. used a PIC18F248 and made a eeprom programmer/Reader well im not done coding but the hardware is done. Im making the UART part of the program now. Since it was a SOIC i had to cut the circles in half so it can fit.

xee_01-jpg.21244


xee_02-jpg.21245


xee_03-jpg.21246
 

Attachments

  • xee_01.jpg
    xee_01.jpg
    222.2 KB · Views: 336
  • xee_02.jpg
    xee_02.jpg
    72.9 KB · Views: 286
  • xee_03.jpg
    xee_03.jpg
    98.5 KB · Views: 297
Last edited:
Since it was a SOIC i had to cut the circles in half so it can fit.
Isn't that cute! :D What's with the round boards?

Cutting the pads in half is pretty ingenious. I wouldn't have thought of that. Might try it sometime...

If you're getting into SOIC, these boards are great! Fairly inexpensive too.

I have some very good advice for you (someone else gave it to me a while back). Get yourself a roll or two of wire wrapping wire (the link is to green, but they have other colors). It's 30 gauge, tinned, easy to strip. The insulation is high temperature tolerant so the iron doesn't melt it. Thin and flexible. Works great for point-to-point wiring. It's so thin that desoldering and making changes is totally easy.

Here's what it looks like in action:
**broken link removed**
 
Last edited:
i was actually going to place a order tomorrow for about 3 of those and some more 18F248's (SOIC). I like SOIC smaller. Even tho its harder lol. As for the wire ill be sure to get that wire but from Radio Shack (not so evil) since 50ft is $4 about same if you think but no Shipping and Handling lol. Not to try and dis them but Sparkfun is expensive!
 
i was actually going to place a order tomorrow for about 3 of those and some more 18F248's (SOIC).
DipMicro only has three 18F248's left. I took the other three he had, so I have four in reserve. Got three more of the boards so I can use them up easily. Digikey is still charging $11 for those, so $3.50 is a great deal.

I like SOIC smaller. Even tho its harder lol.
I like em too. And I don't think they're harder at all. Oh ya, I have to take off my glasses and squint a bit more to count pins, but that's not such a big deal. :p

As for the wire ill be sure to get that wire but from Radio Shack (not so evil) since 50ft is $4 about same if you think but no Shipping and Handling lol. Not to try and dis them but Sparkfun is expensive!
Sparkfun IS expensive, but I like them. Great selection of cool toys.

Rat Shack has wire-wrap wire? I'm shocked! Here in Canada they're called The Source now, and they suck more than ever. They still have a few odd useful parts though.

EDIT: Went to The Source's web-site and they do list wire-wrap wire (at $6.00 - typical ripoff) and the tool. Maybe I'll drop in there and see if they actually have it on the shelf.

I remember when I was a kid, their catalog would come out each year and I'd spend hours going through it. Now they're a crappy toy store with some fairly lame, overpriced electronics.
 
Last edited:
lol yeah they do suck but like you said they still have some off parts like those rounds pcbs i use. They had it in stock but only 1 so i bought it lol. BGMicro for me has superb delivery. It took like 2 days for a order to come in and i ordered on Saturday and it was here Monday. just had to wait for postal office to let me pick it up lol.

Ill be making a nice order from dipmicro later on today like at 7pm (it takes 1 week for delivery from him) Ill be ordering from futurlec and microchip maybe. Oh yeah i found this place online for nice stuff **broken link removed** since its in car distance like 15min im going to call to see if its a store front also. This way i can pay and get stuff (glcds, touch overlays) in person and not have to wait.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top