Unverified Commit 97f9465f authored by Athokshay Ashok's avatar Athokshay Ashok Committed by GitHub
Browse files

Add files via upload

parents
This diff is collapsed.
#ifndef __STM32L476G_DISCOVERY_LCD_H
#define __STM32L476G_DISCOVERY_LCD_H
#include <stdint.h>
#define bool _Bool
void LCD_Initialization(void);
void LCD_bar(void);
void LCD_Clock_Init(void);
void LCD_PIN_Init(void);
void LCD_Configure(void);
void LCD_Clear(void);
void LCD_DisplayString(uint8_t* ptr);
void LCD_WriteChar(uint8_t* ch, bool point, bool colon, uint8_t position);
static void LCD_Conv_Char_Seg(uint8_t* c,bool point,bool colon, uint8_t* digit);
void LCD_Display_Name(void);
#endif /* __STM32L476G_DISCOVERY_LCD_H */
#include "LED.h"
//******************************************************************************************
// User LEDs:
// LD4 Red = PB2 LD5 Green = PE8
// Note: The Green LED is yellow on my board.
// PE8 is also the TIM1_CH1N for ADC Triggers.
//******************************************************************************************
void LED_Init(void){
// Enable the peripheral clock of GPIO Port
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN | RCC_AHB2ENR_GPIOEEN;
///////////////////////////////////////////////////////////////////////////////////////////////
// LD4 Red = PB2
///////////////////////////////////////////////////////////////////////////////////////////////
// GPIO Mode: Input(00), Output(01), AlterFunc(10), Analog(11, reset)
GPIOB->MODER = ~(3U<<(2*2));
GPIOB->MODER |= 1U<<(2*2); // Output(01)
// GPIO Speed: Low speed (00), Medium speed (01), Fast speed (10), High speed (11)
GPIOB->OSPEEDR &= ~(3U<<(2*2));
GPIOB->OSPEEDR |= 3U<<(2*2); // High speed
// GPIO Output Type: Output push-pull (0, reset), Output open drain (1)
GPIOB->OTYPER &= ~(1U<<2); // Push-pull
// GPIO Push-Pull: No pull-up, pull-down (00), Pull-up (01), Pull-down (10), Reserved (11)
GPIOB->PUPDR &= ~(3U<<(2*2)); // No pull-up, no pull-down
///////////////////////////////////////////////////////////////////////////////////////////////
// LD5 Green = PE8
///////////////////////////////////////////////////////////////////////////////////////////////
// GPIO Mode: Input(00), Output(01), AlterFunc(10), Analog(11, reset)
GPIOE->MODER = ~(3U<<(2*8));
GPIOE->MODER |= 1U<<(2*8); // Output(01)
// GPIO Speed: Low speed (00), Medium speed (01), Fast speed (10), High speed (11)
GPIOE->OSPEEDR &= ~(3U<<(2*8));
GPIOE->OSPEEDR |= 3U<<(2*8); // High speed
// GPIO Output Type: Output push-pull (0, reset), Output open drain (1)
GPIOE->OTYPER &= ~(1U<<8); // Push-pull
// GPIO Push-Pull: No pull-up, pull-down (00), Pull-up (01), Pull-down (10), Reserved (11)
GPIOE->PUPDR &= ~(3U<<(2*8)); // No pull-up, no pull-down
}
//******************************************************************************************
// Turn Red LED On
//******************************************************************************************
void Red_LED_On(void){
GPIOB->ODR |= GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Turn Red LED Off
//******************************************************************************************
void Red_LED_Off(void){
GPIOB->ODR &= ~GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Toggle Red LED
//******************************************************************************************
void Red_LED_Toggle(void){
GPIOB->ODR ^= GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Turn Green LED On
//******************************************************************************************
void Green_LED_On(void){
GPIOE->ODR |= GPIO_ODR_ODR_8;
}
//******************************************************************************************
// Turn Green LED Off
//******************************************************************************************
void Green_LED_Off(void){
GPIOE->ODR &= ~GPIO_ODR_ODR_8;
}
//******************************************************************************************
// Toggle Green LED
//******************************************************************************************
void Green_LED_Toggle(void){
GPIOE->ODR ^= GPIO_ODR_ODR_8;
}
#ifndef __STM32L476G_DISCOVERY_LED_H
#define __STM32L476G_DISCOVERY_LED_H
#include "stm32l476xx.h"
void LED_Init(void);
void Red_LED_Off(void);
void Red_LED_On(void);
void Red_LED_Toggle(void);
void Green_LED_On(void);
void Green_LED_Off(void);
void Green_LED_Toggle(void);
#endif /* __STM32L476G_DISCOVERY_LED_H */
//************************************* 32L476GDISCOVERY ***************************************************************************
// STM32L4: STM32L476VGT6 MCU = ARM Cortex-M4 + FPU + DSP,
// LQFP100, 1 MB of Flash, 128 KB of SRAM
// Instruction cache = 32 lines of 4x64 bits (1KB)
// Data cache = 8 lines of 4x64 bits (256 B)
//
// Joystick (MT-008A):
// Right = PA2 Up = PA3 Center = PA0
// Left = PA1 Down = PA5
//
// User LEDs:
// LD4 Red = PB2
// LD5 Green = PE8
//
// CS43L22 Audio DAC Stereo (I2C address 0x94):
// SAI1_MCK = PE2 SAI1_SD = PE6 I2C1_SDA = PB7 Audio_RST = PE3
// SAI1_SCK = PE5 SAI1_FS = PE4 I2C1_SCL = PB6
//
// MP34DT01 Digital MEMS microphone
// Audio_CLK = PE9 Audio_DIN = PE7
//
// LSM303C eCompass (a 3D accelerometer and 3D magnetometer module) SPI Interface:
// MAG_DRDY = PC2 MEMS_SCK = PD1 (SPI2_SCK) XL_CS = PE0
// MAG_CS = PC0 MEMS_MOSI = PD4 (SPI2_MOSI) XL_INT = PE1
// MAG_INT = PC1
//
// L3GD20 Gyro (three-axis digital output) SPI Interface:
// MEMS_SCK = PD1 (SPI2_SCK) GYRO_CS = PD7 (GPIO)
// MEMS_MOSI = PD4 (SPI2_MOSI) GYRO_INT1 = PD2
// MEMS_MISO = PD3 (SPI2_MISO) GYRO_INT2 = PB8
//
// ST-Link V2 (Virtual com port, Mass Storage, Debug port):
// USART_TX = PD5 SWCLK = PA14 MFX_USART3_TX MCO
// USART_RX = PD6 SWDIO = PA13 MFX_USART3_RX NRST
// PB3 = 3V3_REG_ON SWO = PB5
//
// Quad SPI Flash Memory (128 Mbit)
// QSPI_CS = PE11 (QUADSPI_NCS) QSPI_D0 = PE12 (QUADSPI_BK1_IO0) QSPI_D2 = PE14 (QUADSPI_BK1_IO2)
// QSPI_CLK = PE10 (QUADSPI_CLK) QSPI_D1 = PE13 (QUADSPI_BK1_IO1) QSPI_D3 = PE15 (QUADSPI_BK1_IO3)
//
// LCD (24 segments, 4 commons, multiplexed 1/4 duty, 1/3 bias) on DIP28 connector
// VLCD = PC3
// COM0 = PA8 COM1 = PA9 COM2 = PA10 COM3 = PB9
// SEG0 = PA7 SEG6 = PD11 SEG12 = PB5 SEG18 = PD8
// SEG1 = PC5 SEG7 = PD13 SEG13 = PC8 SEG19 = PB14
// SEG2 = PB1 SEG8 = PD15 SEG14 = PC6 SEG20 = PB12
// SEG3 = PB13 SEG9 = PC7 SEG15 = PD14 SEG21 = PB0
// SEG4 = PB15 SEG10 = PA15 SEG16 = PD12 SEG22 = PC4
// SEG5 = PD9 SEG11 = PB4 SEG17 = PD10 SEG23 = PA6
//
// USB OTG
// OTG_FS_PowerSwitchOn = PA9
// OTG_FS_OverCurrent = PC10
// OTG_FS_VBUS = PC11
// OTG_FS_ID = PA10 (OTG_FS_ID)
// OTG_FS_DM = PA11 (OTG_FS_DM)
// OTG_FS_DP = PA12 (OTG_FS_DP)
//
// PC14 = OSC32_IN PC15 = OSC32_OUT
// PH0 = OSC_IN PH1 = OSC_OUT
//
// PA4 = DAC1_OUT1 (NLMFX0 WAKEUP) PA5 = DAC1_OUT2 (Joy Down)
// PA3 = OPAMP1_VOUT (Joy Up) PB0 = OPAMP2_VOUT (LCD SEG21)
//
//****************************************************************************************************************
#include "stm32l476xx.h"
#include "lcd.h"
#include "LCD.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void Joystick_Initialization(void);
void Translate_Morse(void);
void SysTick_Initialize(uint32_t ticks);
void Delay(uint32_t nTime);
void SysTick_Handler(void);
void greenLED_On(void);
void greenLED_Off(void);
void redLED_On(void);
void redLED_Off(void);
void movingString(uint8_t* str, uint8_t len);
uint8_t curr_index;
uint8_t * string;
uint8_t length;
uint16_t morse;
volatile uint32_t time;
int main(void)
{
Joystick_Initialization();
LCD_Initialization();
SysTick_Initialize(4000);
string = malloc (6 * sizeof(uint8_t));
while (1)
{
uint16_t joystick_center = (((GPIOA->IDR) & (0x1 << 0)) >> 0);
uint16_t joystick_left = (((GPIOA->IDR) & (0x1 << 1)) >> 1);
uint16_t joystick_right = (((GPIOA->IDR) & (0x1 << 2)) >> 2) ;
uint16_t joystick_up = (((GPIOA->IDR) & (0x1 << 3)) >> 3) ;
uint16_t joystick_down = (((GPIOA->IDR) & (0x1 << 5)) >> 5) ;
if (joystick_center == 1)
{
morse = (morse * 10) + 1;
redLED_On();
Delay(500);
redLED_Off();
}
else if (joystick_left == 1)
{
morse = morse / 10;
redLED_On();
Delay(500);
redLED_Off();
}
else if (joystick_right == 1)
{
morse = morse * 10;
redLED_On();
Delay(500);
redLED_Off();
}
else if (joystick_up == 1)
{
greenLED_On();
Delay(500);
greenLED_Off();
morse = (morse * 10) + 3;
}
else if (joystick_down == 1)
{
greenLED_On();
Delay(500);
greenLED_Off();
LCD_Clear();
movingString(string, length);
if (length > 6)
{
uint8_t * temp = malloc (6 * sizeof(uint8_t));
temp [5] = string [length - 1];
temp [4] = string [length - 2];
temp [3] = string [length - 3];
temp [2] = string [length - 4];
temp [1] = string [length - 5];
temp [0] = string [length - 6];
movingString(temp, 6);
//free(temp);
}
else
{
movingString(string, length);
}
}
if (morse >= 10000)
{
Translate_Morse();
if (length > 6)
{
uint8_t * temp = malloc (6 * sizeof(uint8_t));
temp [5] = string [length - 1];
temp [4] = string [length - 2];
temp [3] = string [length - 3];
temp [2] = string [length - 4];
temp [1] = string [length - 5];
temp [0] = string [length - 6];
movingString(temp, 6);
//free(temp);
}
else
{
movingString(string, length);
}
}
}
}
void Joystick_Initialization(void)
{
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
//Enable joystick middle: PA0
GPIOA->MODER &= ~(0x03<<(2*0)) ;
//Enable joystick left: PA1
GPIOA->MODER &= ~(0x03<<(2*1)) ;
GPIOA->PUPDR |= (0x02<<(2*1)) ;
//Enable joystick right: PA2
GPIOA->MODER &= ~(0x03<<(2*2)) ;
GPIOA->PUPDR |= (0x02<<(2*2)) ;
//Enable joystick up: PA3
GPIOA->MODER &= ~(0x03<<(2*3)) ;
GPIOA->PUPDR |= (0x02<<(2*3)) ;
//Enable joystick down: PA5
GPIOA->MODER &= ~(0x03<<(2*5)) ;
GPIOA->PUPDR |= (0x02<<(2*5)) ;
}
void Translate_Morse(void)
{
if (morse == 13000)
{
string[curr_index] = 'A';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31110)
{
string[curr_index] = 'B';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31310)
{
string[curr_index] = 'C';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31100)
{
string[curr_index] = 'D';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 10000)
{
string[curr_index] = 'E';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11310)
{
string[curr_index] = 'F';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33100)
{
string[curr_index] = 'G';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11110)
{
string[curr_index] = 'H';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11000)
{
string[curr_index] = 'I';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13330)
{
string[curr_index] = 'J';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31300)
{
string[curr_index] = 'K';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13110)
{
string[curr_index] = 'L';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33000)
{
string[curr_index] = 'M';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31000)
{
string[curr_index] = 'N';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33300)
{
string[curr_index] = 'O';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13310)
{
string[curr_index] = 'P';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33130)
{
string[curr_index] = 'Q';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13100)
{
string[curr_index] = 'R';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11100)
{
string[curr_index] = 'S';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 30000)
{
string[curr_index] = 'T';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11300)
{
string[curr_index] = 'U';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11130)
{
string[curr_index] = 'V';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13300)
{
string[curr_index] = 'W';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31130)
{
string[curr_index] = 'X';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31330)
{
string[curr_index] = 'Y';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33110)
{
string[curr_index] = 'Z';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 13333)
{
string[curr_index] = '1';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11333)
{
string[curr_index] = '2';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11133)
{
string[curr_index] = '3';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11113)
{
string[curr_index] = '4';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 11111)
{
string[curr_index] = '5';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 31111)
{
string[curr_index] = '6';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33111)
{
string[curr_index] = '7';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33311)
{
string[curr_index] = '8';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33331)
{
string[curr_index] = '9';
curr_index ++;
length ++;
morse = 0;
}
else if (morse == 33333)
{
string[curr_index] = '0';
curr_index ++;
length ++;
morse = 0;
}
morse = 0;
}