Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys, I was wondering if somebody could spot my mistake(s)...

All i'm trying to do is send a byte over a 4 bit data line in C(also with an enable line). Its quite fustrating because If I send EITHER the upper or lower nibble (with a longer delay and some LEDs) the data of both nibbles comes out as planned. Its when I try to send them consecutively in a switch statement things seem to go a bit pear shaped...and heres the code...

C#
case 0x02:                         //case 0x02 from firmware
        IDENT_PORT = 0X00;
        j = 0x16;                  // bit mask ie, & with 1111 0000 to clear bottom nibble
        upper_nibble = j & 0x0f0;  // 0001 0110
        PORTB = upper_nibble;      // present upper nibble on port b
        RB1 = 1;                   // pulse enable line
        DelayUs(100);
        RB1 = 0;
        DelayUs(100);
        k = (j << 4) | (j >> 4);   // swap upper and lower nibbles of 0x16
        lower_nibble = k & 0x0f0;  // again bit mask to leave the lower nibble (0110)
        PORTB = lower_nibble;      // put on port
        RB1 = 1;
        DelayUs(100);              // pulse enable line
        RB1 = 0;
        DelayUs(100);
        PORTB = 0x00;              // clear port
        break;


If I can provide any other info PLEASE let me know.

Any suggestions would be appriciated, as I'm about to start banging my head against a wall!

Thanks
M.
Posted
Updated 27-Jul-11 6:17am
v4

1 solution

Sounds like your code tells the bytes to send, but does not wait for them, and so they collide if you don't pause.
 
Share this answer
 
Comments
kutalinelucas 27-Jul-11 10:26am    
To be honest i'm just being quite tight with my pins! I've tried all sorts of delays but nothing seems to be reliable enough...I'm using a pic18f to speak to 5 bs-2 chips, so i'm being a pin tight with my pins! so is the best way to fix this to use some sort of handshaking, where a the lower nibble would be held until the stamp confirms the upper nibble has been recieved?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900