Code:
#include <stdio.h>
int main(void)
{
/******************* Declare the port addresses **********************/
unsigned char *DDRA = (unsigned char *)0x0002;
unsigned char *PORTB = (unsigned char *)0x0001;
unsigned char *DDRB = (unsigned char *)0x0003;
unsigned char *PTH = (unsigned char *)0x0260;
unsigned char *DDRH = (unsigned char *)0x0262;
unsigned char *PERH = (unsigned char *)0x0264;
/******************* Declare functions*******************************/
unsigned char threshold;
unsigned char read;
unsigned char index;
/************************** Scanner Data ******************************/
unsigned char scanner[ 255 ] = { 50,
4, 9, 14, 18, 23, 26, 29, 30, 31, 32,
34, 37, 41, 47, 54, 63, 71, 80, 87, 92,
94, 94, 92, 89, 85, 83, 83, 86, 93,102,
115,128,141,153,161,164,164,160,152,144,
137,132,132,136,146,161,178,196,213,226
};
/******************* Set up I/O ports ********************************/
*DDRH = 0x00; /* make Port H an input port */
*PERH = 0xFF; /* enable Port H */
*DDRA = 0xFF; /* make Port A an output port */
*DDRB = 0xFF; /* make Port B an output port */
/******************* Main loop ***************************************/
*PORTB = 255; // This clears the display on PORTB //
threshold = *PTH; // Make PORTH equal to threshold //
read = scanner[0];
index = 1;
do
{
*PORTB = pattern (scanner[index]/32);
wait (1);
}
while
((index<=scanner[0]) && (read<threshold));
if ((index < threshold))
{
printf("threshold reached at reading %d with a current value % d.",index ,scanner[index] );
}
else
{
printf (" Threshold not reached after %d readings." ,scanner[255]);
}
return 0 ;
}
/******************* Pattern Function **********************************/
void pattern (char threshold)
{
unsigned char LedTable [8] = { 0b00000001, 0b00000011, 0b00000111, 00001111,
0b00011111, 0b00111111, 0b01111111, 0b11111111 };
unsigned char index;
unsigned char display;
unsigned char sw_on;
unsigned char sw_off;
index = threshold;
sw_on = ((unsigned char) LedTable[index]);
sw_off = threshold & 0b11111111;
if ( sw_off & 0b00010000)
{
display = sw_on | 0b10000000 ;
}
else
{
display = sw_on & 0b01111111;
}
}
/********************** Wait Function **********************************/
void wait (int seconds)
{
unsigned int i;
unsigned int j;
unsigned int k;
for ( k = 0; k <= seconds; k++)
{
for ( i = 0; i <= 50; i++)
{
for (j =0; j <= 2000; j++);
}
}
}
Any help would be much appreciated...