|
|
View previous topic :: View next topic |
Author |
Message |
Petri Guest
|
SPI problem |
Posted: Wed Nov 28, 2001 2:39 pm |
|
|
It was a first time to use SPI so I have a problem to write MAX7219 7-seg chip. Maybe someone could told me what I do wrong, below is the code. I try to use function like write_ext_seg(12,0x01); but i cant display any number.
//////////////////////////////////////////////////
I use 16F628 chip.
Code:
#define seg_SELECT PIN_B6
#define seg_DI PIN_B7
#define seg_DO PIN_B4
#define seg_CLK PIN_B5
const byte command_table[14]={ 0b00000000, // 0 cmd(0)
0b00000001, // 1
0b00000010, // 2
0b00000011, // 3
0b00000100, // 4
0b00000101, // 5
0b00000110, // 6
0b00000111, // 7
0b00001000, // 8
0b00001001, // 9
0b00001010, // 10
0b00001011, // 11
0b00001100, // 12 =XC
0b00001111}; // 13
void write_ext_seg(byte address, byte data) {
byte cmd[2];
byte i;
cmd[0]=data;
cmd[1]=command_table[address];
//output_high(seg_SELECT);
output_low(seg_DI);
output_low(seg_CLK);
output_low(seg_SELECT);
for(i=1;i<=16;++i){
output_bit(seg_DI,shift_left(cmd,2,0));
output_high(seg_CLK);
output_low(seg_CLK);
}
output_low(seg_DI);
output_high(seg_SELECT); // load serial data
delay_ms(11);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 1357 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: SPI problem |
Posted: Wed Nov 28, 2001 4:04 pm |
|
|
<font face="Courier New" size=-1>I use this to write a word over SPI. It's almost identical to what you use except there are delays to allow the pins time to change as well as the method of addressing the variable.
long int DACbuffer; //16 bit variable Write to DAC. Only 14 bits used.
int shiftbit; //shift variable
// DAC_CS pin A3,DAC_Din pin A4,DAC_CLK pin A5
output_high(PIN_A3);
for(shiftbit=1;shiftbit<=16;++shiftbit)
{
output_bit(PIN_B4,shift_left(&DACbuffer,2,0));
delay_cycles(1);
output_high(PIN_B5);
delay_cycles(1);
output_low(PIN_B5);
}
output_low(PIN_A3);
___________________________
This message was ported from CCS's old forum
Original Post ID: 1360 |
|
|
|
|
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
|