View previous topic :: View next topic |
Author |
Message |
Atma
Joined: 08 Aug 2005 Posts: 22
|
source code for timing diagram |
Posted: Wed Sep 07, 2005 4:44 am |
|
|
hi there
I am trying to write a program for the timing diagram figure 6.1 in manual 39025f.pdf related to the PIC16F873 in C but have no idea how to go about doing that. Can some one tell me how to write the source code? thanks
All help will be appreciated. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Sep 08, 2005 1:37 pm |
|
|
Take a careful look at the timing diagram, then write code to do what's in it.
For example, both the data & clock lines must be low before MCLR is set high. They must also be low for at least 100 ns before MCLR is raised (tset0 from Table 6-1).
This would be coded something like:
Code: | output_low(CLOCK_PIN);
output_low(DATA_PIN);
delay_us(1); // only have to delay for 100 ns, but this will make sure the delay is enough
output_high(MCLR_PIN); |
You'll have to define CLOCK_PIN etc to correspond to individual pins on the programming PIC.
From the diagram, once the above instructions have executed, everything then must "hold" for thold0. From Table 6-1, thold0 is at least 5 us.
Now you'd add the following line to account for this delay:
Code: | delay_us(7); // 7 is "at least" 5, plus some padding, just in case |
And so on, and so on, and so on. |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Mon Sep 12, 2005 8:16 am |
|
|
newguy wrote: | Take a careful look at the timing diagram, then write code to do what's in it.
For example, both the data & clock lines must be low before MCLR is set high. They must also be low for at least 100 ns before MCLR is raised (tset0 from Table 6-1).
This would be coded something like:
Code: | output_low(CLOCK_PIN);
output_low(DATA_PIN);
delay_us(1); // only have to delay for 100 ns, but this will make sure the delay is enough
output_high(MCLR_PIN); |
You'll have to define CLOCK_PIN etc to correspond to individual pins on the programming PIC.
From the diagram, once the above instructions have executed, everything then must "hold" for thold0. From Table 6-1, thold0 is at least 5 us.
Now you'd add the following line to account for this delay:
Code: | delay_us(7); // 7 is "at least" 5, plus some padding, just in case |
And so on, and so on, and so on. |
hi there
thanks for the answer.
I have done that. Where i am confused is where i have to send a 14 bit data word when the clock cycle completes 16 cycles. How do i go about doing that ?
thanks |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Mon Sep 12, 2005 11:04 am |
|
|
Someone else will have to help you here. The two extra bits are a start bit tacked onto the beginning and a stop bit tacked onto the end. The documentation does describe them. What's not clear, from my (quick) perusal of the documentation and the timing diagram, is what the start & stop bits should be - high or low.
The timing diagram seems to indicate that the start & stop bits may be high or low. Perhaps it doesn't matter? Try it with them high, low, or some combination to see if it works or not. |
|
|
Guest
|
|
Posted: Mon Sep 12, 2005 11:07 am |
|
|
newguy wrote: | Someone else will have to help you here. The two extra bits are a start bit tacked onto the beginning and a stop bit tacked onto the end. The documentation does describe them. What's not clear, from my (quick) perusal of the documentation and the timing diagram, is what the start & stop bits should be - high or low.
The timing diagram seems to indicate that the start & stop bits may be high or low. Perhaps it doesn't matter? Try it with them high, low, or some combination to see if it works or not. |
but then how do i code it in c? thats where i am confused. whats the code i would use in c to append the start and stop bis and the rest of the data word?
thanks |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Mon Sep 12, 2005 11:44 am |
|
|
Anonymous wrote: | newguy wrote: | Someone else will have to help you here. The two extra bits are a start bit tacked onto the beginning and a stop bit tacked onto the end. The documentation does describe them. What's not clear, from my (quick) perusal of the documentation and the timing diagram, is what the start & stop bits should be - high or low.
The timing diagram seems to indicate that the start & stop bits may be high or low. Perhaps it doesn't matter? Try it with them high, low, or some combination to see if it works or not. |
but then how do i code it in c? thats where i am confused. whats the code i would use in c to append the start and stop bis and the rest of the data word?
thanks |
You'll need a combination of delay_us() calls, output_high(), output_low(), etc.
Do you know how to program in C |
|
|
|