How to access the input an output register bits using C
What is the most effective way of accessing several outputs or inputs of the PROP chip using the imagecraft C compiler?· I have tried several ways, I used the·blinkLed.c with only one output and had·expected results.· I then modified the code to only blink 1 led on my demo board but, I didn't get good results when I added another output.· I tried creating a structure, but don't know what I am doing wrong.· I hope this is an easy one for one of you, because I am trying to communicate with a DS1620 using the C code.

Comments
#include <propeller.h> void main(void) { int val; DIRA |= 0x5555; // set even number bits to outputs OUTA |= 0x5; // set bit 0 and 2 high OUTA &= 0x4; // set bit 2 low CLR(val, 0); // clear bit 0 SET(val, 0); // set bit 0 FLIP(val,0); // flip bit 0 val = INA; // get input from odd bits + state of output bits }Bit numbers were wrong in CLR/SET/FLIP sorry. Corrected now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (jazzed) : 12/28/2008 9:24:23 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The obex C FullDuplexSerial is the best C serial driver library to use if you don't mind using a Propeller COG (The alternative is the ASIO library). I believe you are on a fair track. A better way (for me at least) would be to use a different kind of command for changing up to 3 bits at once. SET/CLR/FLIP are one bit at a time. Consider this:
// untested but should work #define BITS 0x1c // the long way void setBits(int newbits) { int var = INA; var &= BITS; var |= newbits; OUTA = val; } // alternatively ... void setBits(int newbits) { OUTA = (INA & ~BITS) | newbits; }I hope you get a chance to share DS1620 C library in obex when it is complete.
Best of luck with your project.
Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔