CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Serial to Parallel using PIC and CCSC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pete
Guest







Serial to Parallel using PIC and CCSC
PostPosted: Thu Mar 29, 2007 4:50 am     Reply with quote

Hi!
Can somebody post a code that converts serial data, say 10110010 into parallel that will lit an led corresponding to the serial data? The serial data come into groups of 8bits. Every group of 8 bits, will be displayed in LED in parallel and LED will light by 1 sec on and 1 sec off. For the next group of 8bits serial input, the LED will light again corresponding to the serial inputs. Thanks...
Guest








PostPosted: Thu Mar 29, 2007 5:14 am     Reply with quote

If someone else does this all for you, how are you going to learn about PICs and C programming?
Try and make it work and then post here with what you've tried and what happens if it doesn't work. That way the kind people here will be able to point out your mistakes and your life will be richer for the experience gained.
pete
Guest







re:series to parallel converter using PIC and CCSC
PostPosted: Thu Mar 29, 2007 8:46 am     Reply with quote

This is a test program. I am sending serial bit 101 using x10 protocol in sending 1 and 0 (without the start code, house code and function code). Program below is for the receiver just to received 101 in parallel to 3 LEDs. This works properly receiving 101. For any other 3 bit binary combinations sent, the LEDs doesn't light correctly. Where could be the problem??


#include <16F628A.h>
#include <STDLIB>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=10000000)
int hc[6]={0,0,0,0,0,0};
int i=0;

#int_ext
my_interrupt()
{
hc[i]=input(PIN_B1);
i++;
if(i==5)
{

output_bit(PIN_A0, hc[0]); // led 1
output_bit(PIN_A1, hc[3]);// led 2
output_bit(PIN_A2, hc[4]);// led3

i=0;
}

}

void main()
{
output_a(0b00000); // initialize port A



set_tris_b(0b00000011); // set direction registers
set_tris_a(0b00000); // set direction registers

ext_int_edge(L_to_H | H_TO_L);

enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);


while(true);
}
Guest








PostPosted: Thu Mar 29, 2007 9:38 am     Reply with quote

You appear to be trying to configure the external interrupt for both low-high and high-low edge transitions with:
Code:
ext_int_edge(L_to_H | H_TO_L);

Check the datasheet & you'll find that you can do one OR the other, not both.
I'm not familiar with X10, but presumably the ignoring of some of the pin states in the array hc[] is commected with this.

Additionally, the TRIS configuration is not required as you are using standard IO which means that the compiler will configure the TRIS registers for you, especially as you output from port A before you've configured it's TRIS.

You neet to check, but I bet the compiler will optimise out the line in main that says:
Code:
while(true);

as this has no effect, you need to put something (anything - restart_wdt() for example). Without this it's possible that your main() will end with the CCS default Sleep instruction which is invisibly placed after main to prevent code from falling through and executing random memory.
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Thu Mar 29, 2007 9:58 am     Reply with quote

You cannot use EXT_INT with both rising and falling edges, at least on this part. Also, I don't know why you would need to, you are using 6 transitions to try to store 3 bits. Just pick the active edge and store 3 bits.

Also, even if your both edges routine was working, you light LED's by locations hc[0], hc[3], hc[4]. They would show up in either 0,2,4 or 1,3,5 depending on your protocol.

Also, you are using '#use standard_io' by default by not having a '#use' line stating otherwise, so setting tris_a bits is totally unnecessary after the output_a() command.
pete
Guest







re:series to parallel converter using PIC and CCSC
PostPosted: Thu Mar 29, 2007 4:29 pm     Reply with quote

Thanks for your replies and comments.
I need both positive and negative going edge since I need it to inject the 1ms pulse after each zero crossing of power line. In x10 powerline communications, when you transmit a "1", it is transmitted as "1 0" and for "0" it is transmitted as "0 1". Now this sequences of 1 or 0 is transmitted within 200us after each zero crossing of powerline(I convert it already to square wave for PIC input of zero crossing). Further, the transmiited "1" is represented by 1ms burst of 120khz sine wave. A "0" is represented by no burst. The x10 receiver, demodulates this bursts into TTL level for PIC input.
Now the PIC needs to decode this transmitted bit sequences.

I particularly select those locations of Hc[] since that is my expected times when the sequence 101 can appear in the receiver.

How could then I trigger an input pin RB0 to respond to both positive going and negative going edge of the input?

Is there a limit in CCSC compiler speed to capture this pulses at correct timing that may warrant to use assembly language?
Ttelmah
Guest







PostPosted: Fri Mar 30, 2007 2:13 am     Reply with quote

To detect both edges, you need a different approach. Either an external zero-crossing detecotr, whic generates a pulse to feed the interrupt, or use one of the high four bits on port B, and the 'interrupt on change' feature. realistically, you need to be using external signal conditioning, whichever approach is used, since the 'logic' transitions, will occur at different points on the falling and rising edges of an AC waveform, and will not give good detection of the crossover point.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group