Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#include <stdio.

h>
#include "STM32F7XX.h"

char dataRx;
int time =1000;
int j=0;
char dataTx = '$';
char helloMessage[] = {"HELLO THERE \rToday is..\r"};
int cont = 0;
int conts=0;
int ini = 0;
char limi =9;

//LCD
char clear =0x01;
char home =0x02;
char set = 0x3C;
char disp_on=0x0F;
char disp_off=0x08;
char mode_set1=0x06;
char mode_set2=0x04;
char disp_shift =0x1C;
char disp_shift1=0x18;

char pos_LCD =0;


char wlinea_1 = (0x80 + 7);
char wlinea_2 = (0xC0 + pos_LCD);

void sendMsg(){
int i=0;
int lengthMsg=sizeof(helloMessage);
for (i=0;i<lengthMsg-1;i++){
dataTx = helloMessage[i];
UART4->TDR=dataTx; //REGISTRO AL CUAL SE ESCRIBE
while ((UART4->ISR &= 0x80)==0); // ESPERA A QUE TXE SEA 1
}
}

void comando_lcd (char b){


GPIOB->ODR =b;
GPIOB-> ODR &= ~(1UL<<8);
GPIOB-> ODR |= (1UL<<9);
for (j=0;j<time;j++);
GPIOB->ODR &= ~(1UL<<9);
}

void dato_lcd (char c){


GPIOB->ODR =c;
GPIOB-> ODR |= (1UL<<8);
GPIOB-> ODR |= (1UL<<9);
for (j=0;j<time;j++);
GPIOB->ODR &= ~(1UL<<9);
}

extern "C" {

void SysTick_Handler(void){
if(ini==1){
cont++;
if (cont>999){
conts++;

comando_lcd(wlinea_1);
dato_lcd(conts+48);

if (48+conts>limi-1){

sendMsg();

comando_lcd(wlinea_2+6);
dato_lcd('F');
dato_lcd('i');
dato_lcd('n');

conts=0;
ini=0;
}
cont=0;
}
}
}
void UART4_IRQHandler(void){ //UART interruption implementation

if(UART4->ISR & 0x20){ // RXNE evaluation


dataRx = UART4->RDR; // REGISTRO DEL CUAL SE LEE

}
ini=1;
comando_lcd(clear);
comando_lcd(wlinea_1);
dato_lcd(0+48);
limi=dataRx;
}

int main(void){
//clock eneable puerto A,B Y C
RCC->AHB1ENR |= (1UL<<0);
RCC->AHB1ENR |= (1UL<<1);
RCC->AHB1ENR |= (1UL<<2);

// Configuracion de puertos 0, 4 y 7 como salidas


GPIOB->MODER= 0x555555;
GPIOB->OTYPER=0;
GPIOB->OSPEEDR=0x555555;
GPIOB->PUPDR=0x555555;

//PIN 13 COMO ENTRADA


GPIOC->MODER &= ~(3UL<<2*13);

//SysTick
SysTick_Config (SystemCoreClock/1000);
SystemCoreClockUpdate();

//UART CONFIG (UART_CR1)


RCC->APB1ENR |= 0x80000; // CLOCK PARA UART4
UART4->BRR=0x683; // 9600 BPS
UART4->CR1 |=0x2D; //ENABLES Tx, Rx, Rx interruption RXNEIE AND UE.
//M1 Y M0 ESTAN EN 0,
POR ENDE LA LONGITUD SON 8-BITS

//ENABLES UART4 INTERRUPTION


NVIC_EnableIRQ (UART4_IRQn);

GPIOA->MODER |= (2UL<<2*0); // A0 funcion alternante


GPIOC->MODER |= (2UL<<2*11); // C11 funcion alternante
GPIOA->AFR[0] |= 0x8; //PA0 -> AF8=UART4 TX, AF8=1000 EN AFR0
GPIOC->AFR[1] |= 0x8000; //PC11 -> AF8=UART4 RX, AF8=1000 EN AFR11

comando_lcd(clear);
comando_lcd(home);
comando_lcd(set);
comando_lcd(disp_on);
comando_lcd(mode_set1);
comando_lcd(wlinea_1);

while(true){

}
}

You might also like