Complete the following tasks. Anduino libraries are not allowed. Please use plain c for microcontroller programing. O UN

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Complete the following tasks. Anduino libraries are not allowed. Please use plain c for microcontroller programing. O UN

Post by answerhappygod »

Complete The Following Tasks Anduino Libraries Are Not Allowed Please Use Plain C For Microcontroller Programing O Un 1
Complete The Following Tasks Anduino Libraries Are Not Allowed Please Use Plain C For Microcontroller Programing O Un 1 (59.59 KiB) Viewed 33 times
Create the program that works as follows. Three buttons should control three LEDs. Buttons M1 and M3 are used to select the LED. The M3 button should change the status of the LED (on or off). The text "Menu" should be displayed in the first line of LCD. The second line should consist of two parts. The configurable LED ("LED Yellow: ", "LED Green: " or "LED Red: ") should be shown on the left part. The status of the LED "ON" or "OFF" should be displayed on the right side of the second line
/*
4-Bit 16x2 LCD Example
*/
//#define F_CPU 16000000UL // Not necessary in simulator
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
// Your global variables here
// Defination of pot and pin variables
#define LCD_Port PORTD // Define LCD Port (PORTA, PORTB, PORTC, PORTD)
#define LCD_DPin DDRD // Define 4-Bit Pins (PD4-PD7 at PORT D)
#define LCD_DATA0_PIN PD4 // < pin for 4bit data bit 0
#define LCD_DATA1_PIN PD5 // < pin for 4bit data bit 1
#define LCD_DATA2_PIN PD6 // < pin for 4bit data bit 2
#define LCD_DATA3_PIN PD7 // < pin for 4bit data bit 3
#define RSPIN PD3 // RS Pin
#define ENPIN PD2 // E Pin
int runtime; //Timer for LCD
// LCD initialization function with the minimum commands list
void LCD_Init (void)
{
// Data and control pins as outputs
LCD_DPin |= (1<<LCD_DATA0_PIN)|(1<<LCD_DATA1_PIN)|(1<<LCD_DATA2_PIN)|(1<<LCD_DATA3_PIN)|(1<<RSPIN)|(1<<ENPIN); //Control LCD Pins (D4-D7)
_delay_ms(16); //Wait more when 15 ms after start


LCD_Action(0x02); // Returns the cursor to the home position (Address 0). Returns display to its original state if it was shifted.
LCD_Action(0x28); // Data sent or received in 4 bit lengths (DB7-DB4)
LCD_Action(0x0C); // Display on, cursor off
LCD_Action(0x06); // Increment cursor (shift cursor to right)
LCD_Action(0x01); // Clean LCD
_delay_ms(5);
}
// Function to send commands and data to the LCD
void LCD_Action( unsigned char cmnd )
{
LCD_Port = (LCD_Port & 0x0F) | (cmnd & 0xF0);
LCD_Port &= ~ (1<<RSPIN);
LCD_Port |= (1<<ENPIN);
_delay_us(1);
LCD_Port &= ~ (1<<ENPIN);
_delay_us(200);
LCD_Port = (LCD_Port & 0x0F) | (cmnd << 4);
LCD_Port |= (1<<ENPIN);
_delay_us(1);
LCD_Port &= ~ (1<<ENPIN);
_delay_ms(2);
}
// Clear whole LCD
void LCD_Clear()
{
LCD_Action (0x01); //Clear LCD
_delay_ms(2); //Wait to clean LCD
LCD_Action (0x80); //Move to Position Line 1, Position 1
}
// Prints string of chars
void LCD_Print (char *str)
{
int i;
for(i=0; str!=0; i++)
{
LCD_Port = (LCD_Port & 0x0F) | (str & 0xF0);
LCD_Port |= (1<<RSPIN);
LCD_Port|= (1<<ENPIN);
_delay_us(1);
LCD_Port &= ~ (1<<ENPIN);
_delay_us(200);
LCD_Port = (LCD_Port & 0x0F) | (str << 4);
LCD_Port |= (1<<ENPIN);
_delay_us(1);
LCD_Port &= ~ (1<<ENPIN);
_delay_ms(2);
}
}
// Prints string of chars to the specific location
// row - the row 0 or 1;
// pos - the column from 0 till 16
void LCD_Printpos (char row, char pos, char *str)
{
if (row == 0 && pos<16)
LCD_Action((pos & 0x0F)|0x80);
else if (row == 1 && pos<16)
LCD_Action((pos & 0x0F)|0xC0);
LCD_Print(str);
}
// Your functions here
int main()
{
// Your code here

while(1) {
// Your code here
}
}
Complete the following tasks. Anduino libraries are not allowed. Please use plain c for microcontroller programing. O UNO ARDUINO VilniusTech Menu LED Yellow: OFF
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply