/*
NAME & SURNAME: JACOB NGOBENI
STUDENT NUMBER: 222166134
Assignment Title: Temperature Monitoring and Binary Display with STM32
*/
#pragma GCC push_options
#pragma GCC optimize ("O0")
//include head files
#include "stm32c0xx.h"
#include "stdio.h"
#include <math.h>
int main(void)
{
RCC->AHBENR |= (1UL << 19); // Enable GPIOC clock
RCC->AHBENR |= (1UL << 18); // Enable GPIOB clock
GPIOC->MODER &= ~(3UL << 26); // Clear PC13 mode
GPIOC->MODER |= (0UL << 26); // Set PC13 to input mode
GPIOB->MODER &= ~(3UL << 0); // Clear PB0 mode
GPIOB->MODER |= (1UL << 0); // Set PB0 to output mode
GPIOB->MODER &= ~(3UL << 2); // Clear PB1 mode
GPIOB->MODER |= (1UL << 2); // Set PB1 to output mode
GPIOB->MODER &= ~(3UL << 4); // Clear PB2 mode
GPIOB->MODER |= (1UL << 4); // Set PB2 to output mode
GPIOB->MODER &= ~(3UL << 6); // Clear PB3 mode
GPIOB->MODER |= (1UL << 6); // Set PB3 to output mode
GPIOB->MODER &= ~(3UL << 8); // Clear PB0 mode
GPIOB->MODER |= (1UL << 8); // Set PB0 to output mode
GPIOB->MODER &= ~(3UL << 10); // Clear PB1 mode
GPIOB->MODER |= (1UL << 10); // Set PB1 to output mode
GPIOB->MODER &= ~(3UL << 12); // Clear PB2 mode
GPIOB->MODER |= (1UL << 12); // Set PB2 to output mode
GPIOB->MODER &= ~(3UL << 14); // Clear PB3 mode
GPIOB->MODER |= (1UL << 14); // Set PB3 to output mode
GPIOB->MODER &= ~(3UL << 16); // Clear PB3 mode
GPIOB->MODER |= (1UL << 16); // Set PB3 to output mode
// int i = 0;
//int n;
//int x;
while (1)
{
// if (!(GPIOC->IDR & (1UL << 13)))// If PC13 is high
// {
// if ((GPIOC->IDR & (1UL << 13))) break; // If PC13 is not high,
//break out of the loop
for (int n=0; n<9; n++ )
{
GPIOB->ODR = (1UL<<n);
for (int j = 0; j < 100000; j++); // Delay
}
for (int t=0; t<8; t++ )
{
{
GPIOB->ODR=(0x80UL>>t);
for (int j = 0; j < 100000; j++); // Delay
} }
}
}
/*
int main(void)
{
RCC->AHBENR |= (1UL << 18); // Enable GPIOB clock
GPIOB->MODER &= ~(3UL << 8); // Clear PB4 mode
GPIOB->MODER |= (1UL << 8); // Set PB4 to output mode
GPIOB->MODER &= ~(3UL << 10); // Clear PB5 mode
GPIOB->MODER |= (1UL << 10); // Set PB5 to output mode
GPIOB->MODER &= ~(3UL << 12); // Clear PB6 mode
GPIOB->MODER |= (1UL << 12); // Set PB6 to output mode
GPIOB->MODER &= ~(3UL <<14); // Clear PB7 mode
GPIOB->MODER |= (1UL << 14); // Set PB7 to output mode
GPIOB->MODER &= ~(3UL << 16); // Clear PB8 mode
GPIOB->MODER |= (0UL << 16); // Set PB8 to input mode
RCC->AHBENR |= (1UL << 19); // Enable GPIOC clock
GPIOC->MODER &= ~(3UL << 12); // Clear PC6 mode
GPIOC->MODER |= (1UL << 12); // Set PC6 to output mode
GPIOC->MODER &= ~(3UL << 14); // Clear PC7 mode
GPIOC->MODER |= (1UL << 14); // Set PC7 to output mode
GPIOC->MODER &= ~(3UL << 26); // Clear PC13 mode
GPIOC->MODER |= (0UL << 26); // Set PC13 to input mode
while (1)
{
while ((GPIOB->IDR & (1UL << 8)))// If PB is high
{ if (!(GPIOB->IDR & (1UL << 8))) break;
for (int i = 0; i < 11; i++)
{
GPIOB->ODR = (i<<4);
GPIOC->ODR = 1UL<<7;
for (int j = 0; j < 900000; j++); // Delay
}
for (int t = 10; t >0 ; t--)
{
GPIOB->ODR = (t<<4);
GPIOC->ODR = 1UL<<6;
for (int j = 0; j < 900000; j++); // Delay
}
}
}
}
*/