Academic help online

Academic help online
The task is to write a C program that lights up the LCD panel and the LED’s of the Discovery kit together like an advertisement board. The message on LCD panel is, “Welcome to Chico!”. The algorithm of the main program is as follows. (Total 10 points)

1) Initialize I2C2 peripheral block
2) Initialize GPIOE peripheral block
3) Light up all LED’s
4) Display a message on LCD
5) Pause for 1 second.
6) Turn LED’s off.
7) Clear the message on LCD
8) Pause for 1 second.
9) Go back to Step 3).

The C program that writes a message on the LCD panel is provided as a separate file. This program is complete by itself. The program that lights LED’s is also provided, but this program is only skeletons. Proceed your work in the following order.

1. Run Lab4_LCD.c first on your Discovery kit, and test if it work all right.

2. Based on Homework 3a, complete Lab4_LED.c, a C program that lights up all LED’s on the board. Then test this program on the kit. (4 points)

3. Write one single program, Lab4.c, based on Lab4_LCD.c and Lab4_LED.(6 points)
1) Modify the main program of Lab4_LEC.c to a subroutine, and move it to Lab4_LCD.c. Move also any necessary header files and directives.
2) Modify the main program of Lab4_LCD.c according to the algorithm presented above.
3) The subroutine for pausing for 1 second is provided in the attachment.

5. Lab4.c should not use any exception handlers or the EXTI interrupt or the push button for its operation. If it does, you will lose your points.

READ ALSO :   School of Business

6. Submit both the completed Lab4_LED.c and Lab4.c files. Make sure that the first line of your program, Lab4.c has your name and section number clearly. The work is due at 11:59pm on 11/22/2015 (Sun). Upload your .c file to the BBLearner.

Attachment :
void pause_1second (){
uint32_t i, time;
time=0x020000;
for (i=0; i<time; i++);
}

End.

here are given file

// EECE 237 F15 Lab4_LED.c
//This is the minimum codes in C to drive LED’s.
//
//

#include “stm32f30x_gpio.h”
#include “main.h”
GPIO_InitTypeDef GPIO_InitStructure;
void IO_Init(void); //function prototype

int main(void) {
IO_Init();
GPIOE->ODR = 0x0f00;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void IO_Init() {
/* GPIOE Periph clock enable */
//A student completes this part

/* Configure GPIOE structure*/
//A student completes this part

/*Initialize GPIOE port
GPIO_Init(GPIOE, &GPIO_InitStructure);

}

/*
* EECE 237 F15 Lab4_LCD.c
* LCD drive in C
* This is a test program to write a short message
* on an LCD panel with minimum library functions
*
*/

#include “stm32f30x_gpio.h”
#include “stm32f30x_i2c.h”
#include “main.h”
#include “stdio.h”
#include “string.h”

GPIO_InitTypeDef GPIO_InitStructure;

void I2C2_init(void);
void LCD_write(int,int, char);
void LCD_clear(void);
void LCD_contrast(int); // Contrast level = 1..50
void LCD_backlight(int); // Backlight level = 1..8
void pause();
char message[16];
char LCD_msg[] = “Wachabanga!”;

int main(void) {
int i, j = 0;
I2C2_init();
while(I2C_GetFlagStatus(I2C2, I2C_ISR_BUSY) != RESET);
LCD_contrast(50);
LCD_backlight(8);
LCD_clear();
for (i=0; i < strlen(LCD_msg); i++)
LCD_write(0, i, LCD_msg[i]);

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void I2C2_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
/* initialize RCC block for I2C2 and GPIOA */
RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* initialize GPIOA[10:9] for I2C alternate function */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_4);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
//
GPIO_Init(GPIOA, &GPIO_InitStructure);
//
/* initializ I2C2 */
I2C_DeInit(I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStructure.I2C_DigitalFilter = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_Timing = 0xC062121F;
//
I2C_Init(I2C2, &I2C_InitStructure);
I2C_Cmd(I2C2, ENABLE);
}

READ ALSO :   Families in the Media

void LCD_write(int row, int col, char data) {
// LCD_clear();
// Move to sepcified row, col
I2C_TransferHandling(I2C2, 0x50 , 3, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0xFE);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0x45);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
if (!row) // if row == 0
I2C_SendData(I2C2, col);
else // else row asumed to be 1
I2C_SendData(I2C2, (0x40 + col));
I2C_TransferHandling(I2C2, 0x50 , 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, data);
pause();
}
//
// Set LCD Contrast – Level should be 1..50 (Seems to work best if > 35)
//
void LCD_contrast(int level) {

I2C_TransferHandling(I2C2, 0x50 , 3, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0xFE);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0x52);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, level);
pause();
}
//
// Set LCD Backlight – Level should be 1..8 (Seems to work best if > 1)
//
void LCD_backlight(int level) {
I2C_TransferHandling(I2C2, 0x50 , 3, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0xFE);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0x53);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, level);
pause();
}

void LCD_clear() {
I2C_TransferHandling(I2C2, 0x50 , 2, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0xFE);
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, 0x51);
pause();
}

void pause (){
uint32_t i, time;
time=0x008000;
for (i=0; i<time; i++);
}

Academic help online