write a program in C that reads an 8-bit number n using a DIP switch pack (8-bit
ID: 3826391 • Letter: W
Question
write a program in C that reads an 8-bit number n using a DIP switch pack (8-bit input) on UNI DS6 board, computes, then stores each Fibonacci number up to number n, to the external 6116 2KB memory block, starting with the first address. Your program should be able to handle 16-bit unsigned numbers. Other requirements are: Your program should compute the Fibonacci sequence; lookup tables are not allowed in any part of the solution. The main Fibonacci computation (of calculating the next number based on the previous two) should be done in a recursive subroutine. The initially entered number n cannot be less than 1. Your program should check this condition. After all numbers are stored to the memory the computed Fibonacci numbers should be read from the memory, and displayed on the LCD display in pairs of numbers with a space in between. There should be about 2 seconds of delay between the display of each pair. For example, for n 3, the numbers are displayed in the following sequence in about 8 seconds: 0 1 1 1 1 2 2 3 A warning message should appear on the LCD display if either of the two final numbers required more than 16 bits.Explanation / Answer
#include <avrio.h>
#include <utildelay.h>
#include "lcd.h"
#define databus_direction DDRB
#define databus PORTB
#define control_bus PORTB
#define rs 0
#define rw 1
#define en 2
/* 16x2 LCD Specification
#define LCDMaxLines 2
#define LCDMaxChars 16
#define LineOne 0x80
#define LineTwo 0xc0
#define BlankSpace ' '
void LCD_Init()
{
_delay_ms(50);
databus_direction = 0xff;
LCD_CmdWrite(0x02);
LCD_CmdWrite(0x28);
LCD_CmdWrite(0x0E);
LCD_CmdWrite(0x01);
LCD_CmdWrite(0x80);
}
void LCD_CmdWrite( char cmd)
{
databus=(cmd & 0xf0);
control_bus &=~(1<<rs);
control_bus &=~(1<<rw);
control_bus |=1<<en;
_delay_us(1);
control_bus &=~(1<<en);
_delay_us(10);
databus=((cmd<<4) & 0xf0);
control_bus &=~(1<<rs);
control_bus &=~(1<<rw);
control_bus |=1<<en;
_delay_us(1);
control_bus &=~(1<<en);
_delay_ms(1);
}
void LCD_DataWrite( char dat)
{
databus=(dat & 0xf0);
control_bus |=1<<rs;
control_bus &=~(1<<rw);
control_bus |=1<<en;
_delay_us(1);
control_bus &=~(1<<en);
_delay_us(10);
databus=((dat <<4) & 0xf0);
control_bus |=1<<rs;
control_bus &=~(1<<rw);
control_bus |=1<<en;
_delay_us(1);
control_bus &=~(1<<en);
_delay_ms(1);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.