![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
anand_manutd Guest
|
8 line display |
Posted: Tue Jun 06, 2006 8:48 pm |
|
|
I was asked to come up with a code to test light a 8 line display.
Each row consist of 16 Led. There are 8 rows
Each row is controlled by a D port pin (as you will see in my codes)
This codes dont seem to work. Please let me know why
Here are my codes
#if defined(__PCM__)
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP, NOBROWNOUT
#use delay(clock=20000000)
#endif
#define Clock PIN_C0 //Made Low and High each data input
#define StrobeControl PIN_C4 //Enable pin
#define Strobe1 PIN_E0 //These 3 pins are
#define Strobe2 PIN_E1 // used to strobes
#define Strobe3 PIN_E2 // of each displays
#define DataRow1 PIN_D0 // D
#define DataRow2 PIN_D1 // A
#define DataRow3 PIN_D2 // T
#define DataRow4 PIN_D3 // A Each controls one row
#define DataRow5 PIN_D4 // P
#define DataRow6 PIN_D5 // I
#define DataRow7 PIN_D6 // N
#define DataRow8 PIN_D7 // S
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
//#define RowLed 16
//#define ColLed 8
void main() {
int Led;
char Pointer,OutRow;
const char Test[1][1]={
0x00FF
};
setup_adc_ports(no_analogs); //to make all IO digital
set_tris_c(0x00); //C0,C4 and C5 are outputs
set_tris_d(0x00); //all D ports are outputs
set_tris_e(0x00); //E0,E1 and E2 are outputs
output_high(StrobeControl); //Strobe for all 8 display is Low
output_low(Strobe1);
output_low(Strobe2);
output_low(Strobe3);
do {
Pointer = Test[0][0];
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow1,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow1, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow2,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow2, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow3,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow3, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow4,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow4, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow5,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow5, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow6,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow6, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow7,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow7, LSB first
output_high(Clock); } //Clock set to high
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow8,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow8, LSB first
output_high(Clock); } //Clock set to high
output_low(StrobeControl); //Strobe made
output_low(Strobe1); // high only
output_low(Strobe2); // for
output_low(Strobe3); // display 1
output_D(0xFF);
//output_D(0x00); //turn it off
//OutRow=OutRow/2;
} while(1);
} |
|
![](templates/subSilver/images/spacer.gif) |
anand_manutd Guest
|
Ask me if wanna know more |
Posted: Tue Jun 06, 2006 8:56 pm |
|
|
![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Leef_me
Joined: 14 Mar 2006 Posts: 45
|
|
Posted: Wed Jun 07, 2006 12:55 am |
|
|
>>anand_manutd
>>I was asked to come up with a code to test light a 8 line display.
>>Each row consist of 16 Led. There are 8 rows
>>Each row is controlled by a D port pin (as you will see in my codes)
>>This codes dont seem to work. Please let me know why
Oh, no. Where do I start?
Well it seems by reading some of your comments, and making guesses that each row consists of a 16 bit shift register, and that each shift register is supposed to be selected by the Strobe1, Strobe2, Strobe3 lines
through a decoder of some sort.
If this is incorrect, please provide a description of your hardware, parts numbers are usually a good thing to include.
If those asumptions are correct and you understand the lows and highs required to drive the shift registers. May I suggest problem areas in you code.
Code: |
const char Test[1][1]={
0x00FF
};
....
Pointer = Test[0][0];
....
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow1,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow1, LSB first
output_high(Clock); } //Clock set to high
|
The above shows that you created a constant character array with one member that has the value 0xff. Then you point to the value and attempt to shift it right (to get the LSB) 16 times. There are problems with this:
the data type character is only 8 bit wide; the value is a constant, so every 'shift_right' will return the same data bit.
Code: |
for(Led=0;Led<16;Led++) {
output_low(Clock); //Clock set to low
output_bit(DataRow1,shift_right(&Pointer,2,0)); //shifts 2 bytes of data into DataRow1, LSB first
output_high(Clock); } //Clock set to high
|
You repeat the above code 8 times (except for 'DataRow2'...'DataRow8'),
but you never change the the Strobe1, Strobe2, Strobe3 lines.
This seems like an mistake.
Code: |
output_high(StrobeControl); //Strobe for all 8 display is Low
output_low(Strobe1);
output_low(Strobe2);
output_low(Strobe3);
|
The first line seems to have a poor comment.
Code: |
output_low(Clock); //Clock set to low
...
output_high(Clock); } //Clock set to high
|
Poor comments. Don't repeat the 'C' function or statement, instead describe why the action is performed. 'Prepare for next data bit'
and 'Rising edge clocks data into shift register'
Code: |
//shifts 2 bytes of data into DataRow8, LSB first
|
This comment is more descriptive of the block of 4 statements,
not of "output_bit(DataRow8,shift_right(&Pointer,2,0));"
Why not try something a little simpler to see if you have things right?
Keep all the instructions setting up 'Clock', 'StrobeControl' and Strobe1 etc.
And temporarily replace the 8 blocks of 4 statements with just one block.
Code: |
for(Led=0;Led<16;Led++) {
output_low(Clock); //Prepare for next data bit
// the LSB of 'Led' determines odd or even value, and is sent to the current shift register
output_bit(DataRow1,bit_test(Led,0));
output_high(Clock); } //clock data into shift register
|
HTH,
Leef_me |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|