Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with Programming code Files needed:https://www.dropbox.com/sh/w01vor8o

ID: 3888395 • Letter: N

Question

Need help with Programming code

Files needed:https://www.dropbox.com/sh/w01vor8oylpo7je/AAC_1j889suf37dRqxEn81xca?dl=0

Makefile:https://www.dropbox.com/s/j8b44sd3h2baa08/makefile?dl=0

#include <avr/io.h>

#include <util/delay.h>

#include <cpu_speed.h>

#include <graphics.h>

#include <lcd.h>

#include <macros.h>

#include "lcd_model.h"

void setup( void ) {

set_clock_speed(CPU_8MHz);

// (a) Enable input from the Left, Right, Up, and Down switches

// of the joystick.

// (b) Initialise the LCD display using the default contrast setting.

// (c) Use one of the functions declared in "graphics.h" to display

// "12345678", using the background colour,

// positioning the left edge of the text at 17 and the nominal top

// of the text at 10.

// (d) Use one of the functions declared in "graphics.h" to copy

// the contents of the screen buffer to the LCD.

}

void process( void ) {

// (e) Determine if the Up joystick switch is closed.

// If it is, set the LCD display to turn off all pixels.

// (f) OTHERWISE, determine if the Down joystick switch

// is closed. If it is, set the LCD display to turn on all pixels.

// (g) OTHERWISE, determine if the Left joystick switch

// is closed. If it is, set the LCD display to enter normal video mode.

// (h) OTHERWISE, determine if the Right joystick switch

// is closed. If it is, set the LCD display to switch to inverse video mode.

// If none of the joystick switches are closed, do nothing.

// (Hint: do not insert any more instructions.)

}

int main(void) {

setup();

for ( ;; ) {

process();

_delay_ms(100);

}

return 0;

}

Explanation / Answer

#include <avr/io.h>
#include <util/delay.h>

#define MrLCDsCrib PORTB
#define DataDir_MrLCDsCrib DDRB
#define MrLCDsControl PORTD
#define DataDir_MrLCDsControl DDRD
#define LightSwitch 5
#define ReadWrite 7
#define BiPolarMood 2

void Check_IF_MrLCD_isBusy(void);
void Peek_A_Boo(void);
void Send_A_Command(unsigned char command);
void Send_A_Character(unsigned char character);
void Send_A_String(char *string);

int main(void)
{
DataDir_MrLCDsControl |= 1<<LightSwitch | 1<<ReadWrite | 1<<BiPolarMood;
_delay_ms(15);

Send_A_Command(0x01); //Clear Screen 0x01 = 00000001
_delay_ms(2);
Send_A_Command(0x38);
_delay_us(50);
Send_A_Command(0b00001110);
_delay_us(50);

Send_A_Character(0x4E); //N
Send_A_Character(0x65); //e
Send_A_Character(0x77); //w
Send_A_Character(0x62); //b
Send_A_Character(0x69); //i
Send_A_Character(0x65); //e
Send_A_Character(0x48); //H
Send_A_Character(0x61); //a
Send_A_Character(0x63); //c
Send_A_Character(0x6B); //k
Send_A_Character(0x2E); //.
Send_A_Character(0x63); //c
Send_A_Character(0x6F); //o
Send_A_Character(0x6D); //m

Send_A_String("Patrick");

while(1)
{
}
}

void Check_IF_MrLCD_isBusy()
{
DataDir_MrLCDsCrib = 0;
MrLCDsControl |= 1<<ReadWrite;
MrLCDsControl &= ~1<<BiPolarMood;

while (MrLCDsCrib >= 0x80)
{
Peek_A_Boo();
}
DataDir_MrLCDsCrib = 0xFF; //0xFF means 0b11111111
}

void Peek_A_Boo()
{
MrLCDsControl |= 1<<LightSwitch;
asm volatile ("nop");
asm volatile ("nop");
MrLCDsControl &= ~1<<LightSwitch;
}

void Send_A_Command(unsigned char command)
{
Check_IF_MrLCD_isBusy();
MrLCDsCrib = command;
MrLCDsControl &= ~ ((1<<ReadWrite)|(1<<BiPolarMood));
Peek_A_Boo();
MrLCDsCrib = 0;
}

void Send_A_Character(unsigned char character)
{
Check_IF_MrLCD_isBusy();
MrLCDsCrib = character;
MrLCDsControl &= ~ (1<<ReadWrite);
MrLCDsControl |= 1<<BiPolarMood;
Peek_A_Boo();
MrLCDsCrib = 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote