AT90S2313-Binary to Graycode
This project shows the conversion of Binary to Gray using Microcontroller AT90S2313.
The program is as shown:
#include AT90S2313.h
unsigned int bin_to_gray(unsigned int n) // function definition
{
return n ^ ( n >> 1 ) // value of ‘n’ is X-ORed with right shifted value of ‘n’
}
int main(void)
{
unsigned int j;
DDRB = 0b00001111;
repeat:
for (j = 0x0 ; j <= 0xF ; j++)
{
PORTB = bin_to_gray(j);
}
goto repeat;
return 0;
}