Вы находитесь на странице: 1из 7

#include <stdio.

h>
#include "STM32F7xx.h"
//-------------------------------------------------------------------
int
numinicio=0,valida1=0,valida2=0,tiempoc=0,segundo=0,habilitador=0,finalizo=1,modoti
tilar=0,titilar=0XFF,tiempot=0,numeral=1;
bool pausa=false;
char datosteclado[2]={'0','0'};
char tecla='N';
int leds[8]={0,1,0x80,0x81,0x4000,0x4001,0x4080,0x4081};
int ingresonumero=0;
int contdisplay[4]={1,2,4,8};
int punto=0;
int s[8]={0xFE,0xFD,0XFB,0XF7,0XEF,0XDF,0XBF,0X7F};
int numerosdisplay[10]={0XC0,0xF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X98};
int numero[4]={0,0,0,0};
int digito=0;
int n=3,pnum=0,w=0,aux=0,ncifras=0,mod=0,div=0,variableaux=0;
int h=0;
void teclado();
void visualdisplay();
void actividad();
char conteo(char N,char MODO);
void reset();
int vnumero(int parametro);
//---------------------------------------------------COMANDOS
TECLADO-----------------------------------------------------------------
bool Systick=0; //Bandera Systick
bool deco=0; //Bandera EXTI
int contiempo=0; //Contador 100 ms
short polling=0; //Contador polling
int intermitencia=0; //Contador por no-interrupcion
bool contreal=0; //Contador para prendido o apagado cada 100 ms
int dato_teclado=0; //Guarda interrupci�n generada por EXTI
void deco_teclado();
int i,j=0, poll,v=0;
int tiempo=0,tiempode=1,tiempov=600;
int filas_mat=0;
char dato=0;
int bandera=0;
int conde=0,habilitador2=0;
//--------------------------------

int igual=0,contador=0;
//---------------------------------------------------
INTERRUPCIONES-------------------------------------------------------------------

extern "C" {
void SysTick_Handler ( void )
{
if(habilitador==1 && pausa==false){
tiempoc++;
if(tiempoc==100){segundo++; tiempoc=0;}
}
if(modotitilar==1 && pausa ==false){
tiempot++;
if(tiempot>150){tiempot=0;}
if(tiempot>100 && tiempot<150){titilar=0x7F;}
else{titilar=0xFF;}
}

polling++;
if(polling>3){ //Reinicia polling
polling=0;
}
contiempo++; //Aumento cada 1 ms

if((GPIOE->IDR & 0x9C00)==0){ //Verifica que no se haya activado


la interrupci�n
intermitencia++;
}

if(contiempo==100){
contiempo=0;
contreal=!(contreal);
}
}

void EXTI15_10_IRQHandler(void)
{
intermitencia=0; //Reinicio debido a interrupci�n
EXTI->PR |= 0x9C00; //limpia las banderas de
la interrupcion C00010 0000 0000 0000
dato_teclado = (GPIOE->IDR & 0x9C00); //decodifica que pin
genero la EXTI
deco=1; //Activo deco teclado
poll=polling;
}
}

//------------------------------------------------Funcion
DELAY-----------------------------------------------------------------------
int delay(int aux){
tiempo = aux;
int j,ms=1000;
for(j=0;j<(tiempo*ms);j++){

}
}

//-------------------------------------------------DECODIFICADO
TECLADO---------------------------------------------------------------
void deco_teclado ( void )
{
while((GPIOE->IDR &0X9C00) !=0)
{
visualdisplay();
}
if(poll==0){ //Columna 4 teclado
switch(dato_teclado) //Evaluo EXTI
{
//funcion();
case 0x400: //1
tecla=1;
dato_teclado=0;
break;
case 0x800: // 2
tecla=2;
dato_teclado=0;
break;
case 0x1000: //3
tecla=3;
dato_teclado=0;
break;
case 0x8000: //A
tecla='A';
pausa=false;
dato_teclado=0;
break;
}

}else if(poll==1){ //Columna 3


switch(dato_teclado)
{
case 0x400: // 4
tecla=4;
dato_teclado=0;
break;
case 0x800: //5
tecla=5;
dato_teclado=0;
break;
case 0x1000: //6
tecla=6;
dato_teclado=0;
break;
case 0x8000: //B
tecla='B';
pausa=true;
dato_teclado=0;
break;
}

}else if(poll==2){ //Columna 2


switch(dato_teclado)
{
case 0x400: //7
tecla=7;
dato_teclado=0;
break;
case 0x800: //8
tecla=8;
dato_teclado=0;
break;
case 0x1000: //9
tecla=9;
dato_teclado=0;
break;
case 0x8000: //C
tecla='C';
dato_teclado=0;
break;
}
}else if(poll==3){ //Columna 1
switch(dato_teclado)
{
case 0x400: //*
tecla='*';
dato_teclado=0;
break;
case 0x800: //0
tecla=0;
dato_teclado=0;
break;
case 0x1000: //#
tecla='#';
tiempot=0;
numeral=1;
pausa=false;
for(i=0;i<3;i++){
numero[i]=0;
}
reset();
modotitilar=0;
dato_teclado=0;
break;
case 0x8000: //D
tecla='D';
dato_teclado=0;
break;
}
}
}

//---------------------------------------------------------
MAIN-----------------------------------------------------------------------

int main(void)
{
RCC->AHB1ENR =0xFF; //RELOJES A,B,C,D,E,F,G

RCC->APB2ENR |= (1UL << 14); //System configuration controller clock enable


//----------------------------------------------------PINES
TECLADO-------------------------------------------------------------------
GPIOE->MODER |= 0x55000; //Pines del PE6 a PE9 como salida y PE10 a
PE12 Y PE15 como entradas
GPIOE->OTYPER = 0;
GPIOE->OSPEEDR |= 0x82AAA000; //High Speed PE6 al PE12 Y PE15
GPIOE->PUPDR = 0x82A55000; //pull up pines del PE6 al PE9 y pull down
del pin PE10 al PE12 Y PE15

GPIOE->ODR &= 0; //inicializa el polling en cero (PE6 a PE9 en


cero)
//-----------------------------------------------------PINES
MATRIZ-------------------------------------------------------------------
//CONTADOR DISPLAY
GPIOC->MODER |= 0x55555555;
GPIOC->OTYPER |= 0;
GPIOC->OSPEEDR |= 0x55555555;
GPIOC->PUPDR |= 0x55555555;
//SEGMENTOS DISPLAY
GPIOD->MODER |= 0x55555555;
GPIOD->OTYPER |= 0;
GPIOD->OSPEEDR |= 0x55555555;
GPIOD->PUPDR |= 0x55555555;
//LEDS
GPIOB->MODER |= 0x55555555;
GPIOB->OTYPER |= 0;
GPIOB->OSPEEDR |= 0x55555555;
GPIOB->PUPDR |= 0x55555555;
//-------------------------------------------------------PINES
LCD--------------------------------------------------------------------
GPIOC->MODER &= ~(3UL << 2*13); //pulsador como entrada (PC13)

//RS=PB8, Enable=PB9, DATA= PB0(LSB)-PB7(MSB)


GPIOG->MODER |= 0x555555; //Pines del PB0 al PB11 como salida
GPIOG->OTYPER |= 0;
GPIOG->OSPEEDR |= 0x555555; //medium speed
GPIOG->PUPDR |= 0x555555; //pull up

SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock/100); //10ms

EXTI->IMR |= 0x9C00; //desenmascara EXTI10-11-12-15


EXTI->RTSR |= 0x9C00; //rising edge PE10-PE11-PE12-PE15

SYSCFG ->EXTICR[2]=0x4400; //EXTI 10 y 11 -> PE EXTICR3 -


PE=0100
SYSCFG ->EXTICR[3]=0x4004; //EXTI 12 y 15 -> PE EXTICR4 -
PE=0100

NVIC_EnableIRQ(EXTI15_10_IRQn); //Habilitar la interrupci�n

//bucle infinito
while(true){
teclado();
if(pausa==false && numeral==1){
actividad();
}
visualdisplay();
}//cierra while
}//cierra main

void teclado(){

if(Systick==0){
switch (polling) //Realizo polling con cambio de columna cada
1ms
{
case 0:
GPIOE->ODR &= ~(1UL << 9);
GPIOE->ODR |= (1UL << 6);
visualdisplay();
break;
case 1:
GPIOE->ODR &= ~(1UL << 6);
GPIOE->ODR |= (1UL << 7);
visualdisplay();
break;
case 2:
GPIOE->ODR &= ~(1UL << 7);
GPIOE->ODR |= (1UL << 8);
visualdisplay();
break;
case 3:
GPIOE->ODR &= ~(1UL << 8);
GPIOE->ODR |= (1UL << 9);
visualdisplay();
break;
default:
break;
}
}
if(deco==1){ //entro a la EXTI
deco_teclado(); //decodifica la tecla
pulsada
deco=0; //reinicio bandera
decodificacion
Systick=0;
}
}

void actividad(){
if((tecla>=0 && tecla<=9) && finalizo==1){datosteclado[0]=tecla; valida1=1;
vnumero(tecla);}
if((tecla=='D' || tecla=='C') && finalizo==1){datosteclado[1]=tecla;
valida2=1;}
//INICIO
if((valida1==1 && valida2==1) && tecla=='A'){
finalizo=0;
conteo(datosteclado[0],datosteclado[1]);
}
}//FIN

char conteo(char N,char MODO){


numinicio=N;
if(MODO=='C'){
habilitador=1;
vnumero(segundo);
if(segundo>(numinicio-1)){finalizo=1; modotitilar=1; reset(); numeral=0;}
}

if(MODO=='D'){
habilitador=1;
vnumero(numinicio-segundo);
if(numinicio-segundo<1){finalizo=1; modotitilar=1; reset(); numeral=0;}
}

}//FIN

void reset(){
habilitador=0;
segundo=0;
valida1=0;
valida2=0;
tecla='N';
}

int vnumero(int parametro){


for(i=0;i<3;i++){
numero[i]=0;
}
ncifras=0;
aux=0;
mod=10;
div=1;
aux=parametro;
//SACAR CIFRAS
while(aux>0){
aux=(aux/10);
ncifras++;
}
for(i=ncifras;i>0;i--){
numero[i-1]=(((parametro%mod))/div);
mod=mod*10;
div=div*10;
}
}

void visualdisplay(){
GPIOC->ODR=contdisplay[h];
if(modotitilar==0){GPIOD->ODR=numerosdisplay[numero[n]];}
if(modotitilar==1){GPIOD->ODR=((numerosdisplay[numero[n]])&titilar);}
n--;
h++;
if(h>3){h=0;}
if(n<0){n=3;}
delay(1);
}

Вам также может понравиться