imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,493
Please let me know I copied a code from internet for subject project and did some changing according to mikroC compiler, it is compiled and run successfully but only one digit is count-up not all other three digits are displaying. Do you know any other code or any link or hint. Two shift registers are used I attached here and also code is attached. Code is written in mikroC.
If I want to use common cathode display so what will changing required in column I also tried digits values in array for common cathode but not working.
If I want to use common cathode display so what will changing required in column I also tried digits values in array for common cathode but not working.
Code:
#define SCLK PORTC.B0 //Serial Clock
#define SDOUT PORTC.B1 //Serial Data Out
#define SDIN PORTC.B2 //Serial Data In
#define CS0 PORTC.B3 //Chip Select
#define CS1 PORTC.B4
//---------------------------DIRECTION------------------------------------------
#define SCLK_dir TRISC.B0
#define SDOUT_dir TRISC.B1
#define SDIN_dir TRISC.B2
#define CS0_dir TRISC.B3
#define CS1_dir TRISC.B4
//------------------------------------------------------------------------------
unsigned int size,offset,Rx,j,pos,count,temp, adc_value; //store output value from Analog Read function
char _data=0;
char* strNum[10]; //Character buffer (see itoa prototype)
//-------------------------Common Anode-----------------------------------------
// 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
unsigned const char digit[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned const char column[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned const char noDigits = 4;
void SPI_init(void)
{
SCLK_dir = 0;
SDOUT_dir = 0;
SDIN_dir = 1;
CS0_dir = 0;
CS1_dir = 0;
}
//--------------------------TX: transmit data-----------------------------------//
void SPI_write(char send)
{
for(j=0;j<8;j++)
{
SCLK = 0;
SDOUT = ((send << j) & 0x80) ? 1 : 0; //MSB first.
SCLK = 1;
}
}
//--------------------------RX: recieve data------------------------------------//
char SPI_read(void)
{
for(Rx = 0 ; Rx < 8 ; Rx++ )
{
SCLK = 0;
_data += (SDIN << (7-Rx)); //MSB first.
SCLK = 1;
}
return _data;
}
void SR_dataSend(char _data)
{
CS0 = 0;
SPI_write(_data);
CS0 = 1;
}
//------------------------------------------------------------------------------
void SR_colSend(char col)
{
CS1 = 0;
SPI_write(col);
CS1 = 1;
}
//------------------------------------------------------------------------------
void SR_colSelect(char col)
{
SR_colSend(column[col]); //Turn particular column On
Delay_ms(5);
SR_colSend(0); //...then turn it Off
}
void segment_display(int number)
{
IntToStr(number,strNum); //Change from Int to C-String (stdlib function)
size = strlen(strNum); //<string.h> function
offset = noDigits - size;
for(pos=0; pos < size; pos++)
{
char index = strNum[pos] - 48; //Decimal 48 is 0 in ASCII
SR_dataSend(digit[index]);
SR_colSelect(pos + offset);
}
}
void main() {
ADCON0 = 0x00;
ADCON2 = 0x26; //
OSCCON = 0x74;
// OSCTUNE = 0x40; // osctune bit 6 is used to activate PLL for internal oscillator
TRISA = 0x01; /*set as input port*/
TRISC = 0x00;
SPI_init();
while(1){
for(count=0; count<10000; count++)
{
segment_display(count);
Delay_ms(20);
}
count=0;
}
}
Attachments
Last edited: