cool.man
Full Member level 6
- Joined
- May 29, 2008
- Messages
- 323
- Helped
- 42
- Reputation
- 84
- Reaction score
- 29
- Trophy points
- 1,308
- Location
- Earth
- Activity points
- 3,307
Hi guys
I am writing a program,which shows some readings on lcd. For testing purpose i am showing 0-9 numbers on LCD as you can see on the image.
i have write a code in ccs c compiler.the code is
Everything is working fine.I just want to know that can i reduce the whole process time below 24mS?
Is there any possibility to reduce the code and time?
I am writing a program,which shows some readings on lcd. For testing purpose i am showing 0-9 numbers on LCD as you can see on the image.
i have write a code in ccs c compiler.the code is
Code:
#include <18f2431.h>
#fuses HS,NOLVP,NOWDT
#USE DELAY (CLOCK=4M)
#define data_pin PIN_A3//data pin for LCD/keypad.
#define clock_pin PIN_A2//clock pin for LCD/keypad.
#define strobe_lcd PIN_A1 //strobe pin for LCD.
////////////////////////////////////////////////////////////////////////////////
//*******************************LCD (BLUE SKY)*********************************
////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------------
// |Position|Position|Position|Position|Position|Position|Position|Position|
// | No | No | No | No | No | No | No | No |
// | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 |
// | | | | | | | | |
// -------------------------------------------------------------------------
// |Position|Position|Position|Position|Position|Position|Position|Position|
// | No | No | No | No | No | No | No | No |
// | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 |
// | | | | | | | | |
// -------------------------------------------------------------------------
// |////////|Position|Position|Position|Position|Position|Position|////////|
// |////////| No | No | No | No | No | No |////////|
// |////////| 05 | 04 | 03 | 02 | 01 | 00 |////////|
// |////////| | | | | | |////////|
// -------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
int1 lcd_data[176]={
// dot, g, f, e, d, c, b, a
0, 0, 0, 0, 0, 0, 0, 0,//00 position
0, 0, 0, 0, 0, 0, 0, 0,//01 position
0, 0, 0, 0, 0, 0, 0, 0,//02 position
0, 0, 0, 0, 0, 0, 0, 0,//03 position
0, 0, 0, 0, 0, 0, 0, 0,//04 position
0, 0, 0, 0, 0, 0, 0, 0,//05 position
0, 0, 0, 0, 0, 0, 0, 0,//06 position
0, 0, 0, 0, 0, 0, 0, 0,//07 position
0, 0, 0, 0, 0, 0, 0, 0,//08 position
0, 0, 0, 0, 0, 0, 0, 0,//09 position
0, 0, 0, 0, 0, 0, 0, 0,//10 position
0, 0, 0, 0, 0, 0, 0, 0,//11 position
0, 0, 0, 0, 0, 0, 0, 0,//12 position
0, 0, 0, 0, 0, 0, 0, 0,//13 position
0, 0, 0, 0, 0, 0, 0, 0,//14 position
0, 0, 0, 0, 0, 0, 0, 0,//15 position
0, 0, 0, 0, 0, 0, 0, 0,//16 position
0, 0, 0, 0, 0, 0, 0, 0,//17 position
0, 0, 0, 0, 0, 0, 0, 0,//18 position
0, 0, 0, 0, 0, 0, 0, 0,//19 position
0, 0, 0, 0, 0, 0, 0, 0,//20 position
0, 0, 0, 0, 0, 0, 0, 0,//21 position
};
int seg_loop,c,b;
int segx[22]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
BYTE CONST segs_7[12]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0x00,0xce};//7-segment values of 0-9
void lcd_print(void)
{
seg_loop=0;
do
{
output_high(clock_pin);//clock signal high
output_bit(data_pin,lcd_data[seg_loop]);//data out
output_low(clock_pin);//clock signal low
seg_loop++;
}while(seg_loop<=175);
output_low(strobe_lcd);//strobe signal low
output_high(strobe_lcd);//strobe signal high
}
void main()
{
segx[0]=9;segx[1]=8;segx[2]=7;segx[3]=6;segx[4]=5;segx[5]=4;
segx[6]=3;segx[7]=2;segx[8]=1;segx[9]=0;segx[10]=1;segx[11]=2;
segx[12]=3;segx[13]=4;segx[14]=5;segx[15]=6;segx[16]=7;segx[17]=8;
segx[18]=9;segx[19]=0;segx[20]=9;segx[21]=8;
while(TRUE)
{
output_toggle(PIN_C0);//just for checking the loop time (approx ~24mS)
c=175;
for(seg_loop=0;seg_loop<22;seg_loop++)
{
b=0b10000000;
do
{
lcd_data[c--]=segs_7[segx[seg_loop]] & b;//storing segments data
//bit-by-bit in an array for sending to LCD.
rotate_right(&b,1);
}while(b!=0b00000001);
c--;
}
output_high(PIN_C1);//just for checking the loop time (approx ~10mS)
lcd_print();
output_low(PIN_C1);//just for checking
}
}
Is there any possibility to reduce the code and time?