Hello guys, am using an AT91M55800A microcontroller on an AT91EB55 board, what i want to try and do is to read an 8 bit binary data from a text file and display it in ASCII characters obviously..
so far i managed to control the lcd defined all the pins and it's workin fine i can display anythin on it now
Code:
#include "AT91M55800A.h"
#include "lib_AT91M55800A.h"
#include "eb55.h"
#include "stdio.h"
#include "lcd.c"
extern void LCD_init (void );
extern void LCD_WriteChar (unsigned int) ;
extern void LCD_command (unsigned int);
extern void LCD_normal (void);
extern void LCD_blink_position (unsigned int, unsigned int);
extern void LCD_display(unsigned int, unsigned int, const char *);
extern int LCD_busy (void);
extern void delay_20ms(void);
int main( void )
{
AT91PS_AIC pAic;
// Load System pAic Base address
pAic = AT91C_BASE_AIC;
//* Init
// First, enable the clock of the PIOB
AT91F_APMC_EnablePeriphClock ( AT91C_BASE_APMC, 1<<AT91C_ID_PIOB ) ;
//LCD init
LCD_init();
//write char, one by one
while(LCD_busy());
LCD_WriteChar(0x1C);
LCD_WriteChar(0x3C);
//blink postion 1,1
LCD_blink_position(1,1);
}
***as u can see from the code that to display any character in ASCII i have to write its value in hex***
**All the pins initialization and the funtion in the lcd.c
the next step i wana try and read a text file with 8 binary numbers and display it on the lcd. i've written a code to change from binary to hex ... but not sure and i havent got a clear idea in my mind what to do.. any help would be appreciated, thank you
the code to change bin2hex:
Code:
#include <stdio.h>
#include <string.h>
int bin2dec(char *bin);
int main()
{
char bin[80] = "";
char *p;
int dec;
while(strcmp(bin,"0"))
{
printf("\n Enter a binary number : ");
fgets(bin, sizeof(bin), stdin);
// check for and remove trailing \n
if ((p = strchr(bin,'\n')) != NULL)
{
*p = '\0';
}
dec = bin2dec(bin);
if (dec) printf("\n Hexadecimal = 0x%02X \n",dec);
}
getchar();
return 0;
}
int bin2dec(char *bin)
{
int b, k, m, n;
int len, sum = 0;
len = strlen(bin) - 1;
for(k = 0; k <= len; k++)
{
n = (bin[k] - '0'); // char to numeric value
if ((n > 1) || (n < 0))
{
puts("\n\n only 1 and 0!\n");
return (0);
}
for(b = 1, m = len; m > k; m--)
{
b *= 2;
}
// sum it up
sum = sum + n * b;
}
return(sum);
}