Sei sulla pagina 1di 5

#include"tm4c123gh6pm.

h"
#include"stdint.h"
/*Funcion de configuracin del UART*/
void config_uart0 (void){
unsigned long temp;
SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART0; // Se activa el reloj del UART
temp = SYSCTL_RCGC2_R; // Espera de unos ciclos de reloj
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA; // Se activa el reloj del puerto A
// PA0
(U0Rx) PA1( U0Tx)
temp = SYSCTL_RCGC2_R; // Espera de unos ciclos de reloj
UART0_CTL_R &= ~ UART_CTL_UARTEN; // Se desactiva el UART
UART0_IBRD_R = (UART0_IBRD_R & ~UART_IBRD_DIVINT_M)|104; // Se configura DIVINT
// 16MHz/(16*9600)
// Parte entera
UART0_FBRD_R = (UART0_FBRD_R & ~UART_FBRD_DIVFRAC_M)|10; //Se configura DIVFRAC
//Parte fraccionaria*64
UART0_LCRH_R = ((UART0_LCRH_R & ~0x000000FF)|(UART_LCRH_WLEN_8)|(UART_LCRH_FEN))
;
// Se configuran
los bits de datos, 1 bit de parada, sin paridad y habilita el FIFO
UART0_CTL_R |= UART_CTL_UARTEN; // Se habilita el UART
GPIO_PORTA_AFSEL_R |= 0x03; // Se activan las funciones alternas de PA0 y PA1.
GPIO_PORTA_DEN_R |= 0x03; // Habilitacin PA0 y PA1 para seales digitales.
}
/*Funcin para la transmisin de un caracter*/
void txcar_uart0(uint8_t car){
while ((UART0_FR_R & UART_FR_TXFF)!=0); //Espera que est disponible para
transmitir
UART0_DR_R = car;
}
/*Funcin para la recepcin de un carcter de 8 bits*/
uint8_t rxcar_uart0(void){
uint8_t temp;
while ((UART0_FR_R & UART_FR_RXFE)!=0); // Se espera que llegue un dato
temp= UART0_DR_R & 0xFF; // Se toman solo 8 bits
return temp;
}
/*Funcion para el envio de una cadena*/
void txmens_uart0(uint8_t mens[]){
uint8_t letra;
uint8_t i=0;
letra= mens[i++];

while (letra != '\0'){ //Se envan todos los caracteres hasta el fin de ca
dena
txcar_uart0(letra);
letra= mens[i++];
}
}
void main(void){
/*Mensajes a utilizar*/
uint8_t nota[5][6]={};
uint8_t promedio[6]={};
uint8_t mNuevo[]="\n\r";
uint8_t mFinal[]="\n\n\rNota final:";
uint8_t mIngresa[]="\n\rDesea agregar notas de otro alumno? S/N\n\r";
uint8_t mInicio[]="\n\r";
uint8_t mInicio2[]="Registro de notas\n\n\r1. Ingrese notas por alumno\n
\r2. Mostrar notas finales\n\r3. Mostrar el porcentaje de aprobados\n\r";
uint8_t mCaso1[]="\n\rIngrese notas\n\r";
uint8_t notasAlumnos[10][6]={};
uint8_t opcion = 0;
uint8_t i = 0,j = 0,k = 0,w,q;
uint8_t empezar,ingreso;
config_uart0();
empezar = rxcar_uart0();
if (empezar == 13)
{
txmens_uart0(mInicio);
txmens_uart0(mInicio2);
while (1)
{
opcion = rxcar_uart0();
while(rxcar_uart0()!=13)
{}
switch(opcion)
{
case '1':
do{
if(j<6)
{txmens_uart0(mCaso1);}
while((k<5) & (j<6))
{
w=0;
notasAlumnos[i][j]=rxcar_uart0();
if(notasAlumnos[i][j]!='F')
{
notasAlumnos[i+1][j]=rxcar_uart0();
if((notasAlumnos[i+1][j]<48)|(notasAlumnos[i+1][
j]>57))
{

w=1;
}
}
else
{
w=1;
}
while(rxcar_uart0()!=13)
{w=w+1;}
if(notasAlumnos[i][j]!='F')
{nota[k][j] = (notasAlumnos[i][j] - 48)*10 + (notasAlumn
os[i+1][j] - 48);}
else
{nota[k][j] = 0;}
if ((nota[k][j]>20) | (w!=0))
{
txmens_uart0("\r");
for(q=0;q<(w+2);q++)
{
txcar_uart0(' ');
}
txmens_uart0("\r");
i=i;
k=k;
}
else
{
txmens_uart0(mNuevo);
i=i+2;
k=k+1;
}
}
if (j<6)
{
promedio[j] = (nota[0][j] + nota[1][j] + nota[2][j] + no
ta[3][j] + nota[4][j])/5;
txmens_uart0(mFinal);
txcar_uart0(0);
txcar_uart0((promedio[j] / 10) + 48);
txcar_uart0((promedio[j] % 10) + 48);
j = j+1;
}
if (j<6)
{
txmens_uart0(mIngresa);
w=0;
do
{
txmens_uart0("\r");
for(q=0;q<(w+1);q++)

{
txcar_uart0(' ');
}
txmens_uart0("\r");
ingreso = rxcar_uart0();
w=0;
while(rxcar_uart0()!=13)
{w=w+1;}
}while(((ingreso!='S')|(ingreso!='N'))&(w!=0));
txmens_uart0(mNuevo);}
else
{
ingreso = 'N';
txmens_uart0(mNuevo);
txmens_uart0("\n\rSe ha ingresado la nota de todos\n\r")
;
}
k=0;
i=0;
}while (ingreso != 'N');
break;
case '2':
txmens_uart0("\n\rAlumnos ingresados: ");
txcar_uart0(j +48);
txmens_uart0("\n\rNotas finales: ");
i=0;
while(i<j)
{
txcar_uart0((promedio[i] / 10) + 48);
txcar_uart0((promedio[i] % 10) + 48);
txcar_uart0(' ');
i=i+1;
}
i=0;
txmens_uart0("\n\r");
break;
case '3':
if (j>0)
{
while(i<j)
{
if(promedio[i] > 10)
{
k=k+1;
}
i=i+1;
}
txmens_uart0("\n\rAprobados: ");
if(k!=j)
{txcar_uart0((((k*100)/j) / 100) + 48);
txcar_uart0((((k*100)/j) / 10) + 48);
txcar_uart0((((k*100)/j) % 10) + 48);

txcar_uart0(37);}
else
{
txmens_uart0("100%");
}
i=0;
k=0;
txmens_uart0("\n\r");
}
else
{
txmens_uart0("\n\rNo se han ingresado alumnos");
}
break;
}
txmens_uart0(mInicio);
txmens_uart0(mInicio2);
}
}
}

Potrebbero piacerti anche