/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <stdint.h>
#include "stm32f103xb.h"
#include "lcd.h"
void delay_ms(uint16_t ms);
void delay_us(uint16_t us);
int main(void)
{
RCC->APB2ENR |= 1 << 2;
RCC->APB2ENR |= 1 << 3;
RCC->APB2ENR |= 1 << 4;
GPIOB->CRL &= ~(0x0F << 0);
GPIOB->CRL |= (0x04 << 0);
LCD_Init();
LCD_Send(0x80, 0);
LCD_Print("Microcontrolador");
LCD_Send(0xC0, 0);
LCD_Print("Tarea 2.1");
uint8_t estado_pantalla = 0;
uint8_t dia = 8, mes = 4;
uint16_t anio = 2026;
uint8_t horas = 23, minutos = 59, segundos = 55;
while ( 1 )
{
if (estado_pantalla == 0)
{
if (GPIOB->IDR & (1 << 0))
{
estado_pantalla = 1;
LCD_Send(0x01, 0);
delay_ms(2);
}
}
else
{
LCD_Send(0x80, 0);
LCD_Print("Fecha:");
LCD_Send('0' + ((dia / 10) % 10), 1);
LCD_Send('0' + (dia % 10), 1);
LCD_Send('/', 1);
LCD_Send('0' + ((mes / 10) % 10), 1);
LCD_Send('0' + (mes % 10), 1);
LCD_Send('/', 1);
LCD_Send('0' + ((anio / 1000) % 10), 1);
LCD_Send('0' + ((anio / 100) % 10), 1);
LCD_Send('0' + ((anio / 10) % 10), 1);
LCD_Send('0' + (anio % 10), 1);
LCD_Send(0xC0, 0);
LCD_Print("Hora:");
LCD_Send('0' + ((horas / 10) % 10), 1);
LCD_Send('0' + (horas % 10), 1);
LCD_Send(':', 1);
LCD_Send('0' + ((minutos / 10) % 10), 1);
LCD_Send('0' + (minutos % 10), 1);
LCD_Send(':', 1);
LCD_Send('0' + ((segundos / 10) % 10), 1);
LCD_Send('0' + (segundos % 10), 1);
delay_ms(1000);
segundos++;
if (segundos >= 60) {
segundos = 0;
minutos++;
if (minutos >= 60) {
minutos = 0;
horas++;
if (horas >= 24) {
horas = 0;
}
}
}
}
}
}
void delay_ms(uint16_t ms) {
volatile unsigned long t = 0;
for(uint16_t i = 0; i < ms; i++)
{
for(t = 0; t < 800; t++);
}
}
void delay_us(uint16_t us)
{
for (volatile unsigned int cycles = 0; cycles < us; cycles++);
}