engineering

| January 13, 2016

Lab #5_Revised  (Due 12/13/15)

 

This is a revision on the previous Lab #5 assignment. The parts revised are in bold.

 

The main program configures SysTick, the pushbutton and the LCD panel, then puts itself in an infinite loop. The task is divided into three parts.

  1. a) Part A: Write a subroutine that beacons all LED at .2 second interval all by itself. The lights flash for 0.1 second.
  2. b) Part B: Write a subroutine that displaces a message on LCD panel, “Red Alert! A tornado coming.” when the pushbutton is pressed.
  3. c) Part C: Once Part A and Part C work, combine them together.

 

Instruction

  1. Do your work in Template-C, nothing else.
  2. The programming is done in C language only.
  3. Do not change the structure of the program. You may add or remove any directives, but shouldn’t change the structure itself.
  4. Add your work of programming to the bottom of the structure where pause_1sec() ends.
  5. Once the program works properly in your Discovery kit, cut and paste your work portion in .doc file and submit the work portion only in BB without the main structure. (This is for grading convenience.)
  6. Clearly put your name, section number and student ID at the beginning of your file.

 

 

 

 

#include “stm32f30x_gpio.h”

#include “main.h”

GPIO_InitTypeDef   GPIO_InitStructure;

RCC_ClocksTypeDef                   RCC_Clocks;

GPIO_InitTypeDef        GPIO_InitStructure;

//

void init_systick(void); //function prototype

void  init_pushbutton(void);

void init_LCD(void);

void init_GPIOE(void);

void IO_Init(void);

void EXTI0_Init(void);

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(void);

void  pause_1sec(void);

char strDisp[20] ;

//volatile variables if any.

//static variables if any.

 

int main(void) {

IO_Init();

while(1);

}

 

/* Initialize I2C2 for LCD panel. */

void I2C2_init(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

I2C_InitTypeDef  I2C_InitStructure;

 

RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

 

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);

}

 

void  LCD_write(int row, int col, char data) {

// 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 == 0 else row asumed to be 1

if (!row) I2C_SendData(I2C2, col)

else  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);

}

//

//

 

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();

}

//

// this pause is for LCD only.

void pause(){

uint32_t i, time;

time=0x20000;

for (i=0; i<time; i++);

}

// Pause for 1 second.

void pause_1sec()  {

uint32_t i, time;

time=0xA00000;

for (i=0; i<time; i++);

}

 

////////////////////////////////////////////////////////

/*  Student’s work start from here.   */

/*      EECE 237 F15 Lab5

*Name:

*Student ID:

*Class section number:

*Submit only this portion of the program to BB.

*/

void IO_Init(void){

//Configure and enable SysTick

init_systick();

//Configure and enable  the push button and LCD panel

init_pushbutton();

init_GPIOE();

init_LCD();

// add as many lines as necessary

 

}

 

//Add other portions of the progrm.

 

 

 

 

 

// The end of student program.

 

—————————————————-

Study the following programs.

void IO_Init() {

GPIOA_Init();

EXTI0_Init();

I2C2_init();

LCD_contrast(50);

LCD_backlight(8);

LCD_clear();

 

/* Get RCC clock frequency */

RCC_GetClocksFreq(&RCC_Clocks);

SysTick_Config(RCC_Clocks.HCLK_Frequency/5);

//5 (=0.2sec) is the smallest number.

 

/* GPIOE Periph clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);

 

/* Configure GPIOE for LED’s */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12| GPIO_Pin_11| GPIO_Pin_10| GPIO_Pin_9| GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

}

 

void GPIOA_Init()  {

GPIO_InitTypeDef   GPIO_InitStructure;

/* Configure PA0 pin as input floating */

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

. . .

. . .

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_4);

. . .

. . .

//

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

 

/* Initialize EXTI0 for the blue button (GPIOA[0]).

* For this, configure SYSCFG and NVIC as well.

*/

void EXTI0_Init() {

EXTI_InitTypeDef   EXTI_InitStructure;

NVIC_InitTypeDef   NVIC_InitStructure;

/* Enable SYSCFG clock */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

/* Connect EXTI0 Line to PA0 pin */

SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

/* Configure EXTI0 line */

EXTI_InitStructure.EXTI_Line = EXTI_Line0;

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

. . .

Get a 5 % discount on an order above $ 150
Use the following coupon code :
2018DISC
project: EM system design & analysis
Project: Experimental determination of a Servo-Motor State Space Model

Category: Homework Help

Our Services:
Order a customized paper today!