/*
 * matri.c
 *
 *  Created on: 9 nov. 2019
 *      Author: David
 */

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MKL25Z4.h"
#include "matri.h"
#include "fsl_debug_console.h"


	void Matrixinit(){
		SIM->SCGC5 |=0x400;
			SIM->SCGC5 |=0x2000;
		/* Inicializamos los pines a utilizar*/
		PORTB->PCR[0] = 0x100; //C1 /* make PTBn pin as GPIO */ //Pines del 16-9 de la matrix
		PORTB->PCR[1] = 0x100; //C2
		PORTB->PCR[2] = 0x100; //C3
		PORTB->PCR[3] = 0x100; //C4
		PORTB->PCR[8] = 0x100; //C5
		PORTB->PCR[9] = 0x100; //C6
		PORTB->PCR[10] = 0x100; //C7
		PORTB->PCR[11] = 0x100; //C8
		PORTE->PCR[2] = 0x100; // R1  /*Make PTC pin as GPIO*/ //Pines del 1-8 de la Matrix
		PORTE->PCR[3] = 0x100; //R2
		PORTE->PCR[4] = 0x100; //R3
		PORTE->PCR[5] = 0x100; //R4
		PORTE->PCR[20] = 0x100; //R5
		PORTE->PCR[21] = 0x100; //R6
		PORTE->PCR[22] = 0x100; //R7
		PORTE->PCR[23] = 0x100; //R8
		PTB->PDDR |= 0xF0F; //Declarando los pines que utilizamos del puerto B como salida
		PTE->PDDR |= 0xF0003C;  //Declarando los pines que utilizamos del puerto C como salida
	}

	void letra_R(char n,int h){
		int l,m,j,i,k,g;
		//Letra R
		if(n=='0'){
			for(int t=0;t<h;t++){
		int Row[]= {0x0,0x700038,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0x700038,0x0};
		int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

				for(m=0;m<8;m++)
				{
					g=m+l;
					PTE->PCOR= Row[g];
					PTE->PSOR= ~Row[g];
					PTB->PSOR= Column[m];
					PTB->PCOR= ~Column[m];
					delayMs(1);

				}
		}
	}else if(n=='1'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x20,0x30,0x18,0xF0003C,0xF0003C,0x0,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='2'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xC00018,0xE0001C,0xF0001C,0xF0002C,0xD0003C,0xC00038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='3'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x400008,0xC0000C,0xD0002C,0xD0002C,0xF0003C,0x700038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='4'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x10003C,0x10003C,0x100020,0x100020,0xF0003C,0xF0003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='5'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x40003C,0xD0003C,0xD0002C,0xD0002C,0xF0002C,0x70000C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='6'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x700038,0xF0003C,0xD0002C,0xD0002C,0xF0002C,0x700004,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='7'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x0,0xC,0xF0000C,0xF0002C,0x3C,0x1C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='8'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x600038,0xF0003C,0x90000C,0x90000C,0xF0003C,0x600038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='9'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x38,0x50003C,0x90000C,0x90000C,0xF0003C,0x700038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='A'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF00038,0xF0003C,0x10000C,0x10000C,0xF0003C,0xF00038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='B'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x90000C,0x90000C,0xF0003C,0x700038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='C'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xC0000C,0xC0000C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='D'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0x700038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='E'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xD0002C,0xD0002C,0xD0002C,0xD0002C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='F'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x10002C,0x10002C,0x10002C,0x10002C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='G'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xD0002C,0xF0002C,0xF0002C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='H'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x100020,0x100020,0xF0003C,0xF0003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='I'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x0,0x0,0xF0003C,0xF0003C,0x0,0x0,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='J'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF00000,0xF00000,0xC00000,0xC00000,0xF0003C,0xF0003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='K'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x300030,0x700038,0xE0001C,0xC0000C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='L'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC00000,0xC00000,0xC00000,0xC00000,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='M'){
		for(int t=0;t<h;t++){
	int Row[]= {0xF0003C,0xF0003C,0x18,0x30,0x30,0x18,0xF0003C,0xF0003C};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='N'){
		for(int t=0;t<h;t++){
	int Row[]= {0xF0003C,0xF0003C,0x38,0x100030,0x300020,0x700000,0xF0003C,0xF0003C};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='O'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0xF0003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='P'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x10000C,0x10000C,0x10003C,0X10003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='Q'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0xF0003C,0xC00000};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='R'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0x30000C,0x70000C,0xD0003C,0x800038,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='R'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x400038,0xC0003C,0xD0002C,0xD0002C,0xF0002C,0x700008,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='T'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xC,0xC,0xF0003C,0xF0003C,0xC,0xC,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='U'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0xF0003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0xF0003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='V'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x70003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0x70003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='V'){
		for(int t=0;t<h;t++){
	int Row[]= {0x0,0x70003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0x70003C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='W'){
		for(int t=0;t<h;t++){
	int Row[]= {0xF0003C,0xF0003C,0x600000,0x300000,0x300000,0x600000,0xF0003C,0xF0003C};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='X'){
		for(int t=0;t<h;t++){
	int Row[]= { 0xC0000C, 0xE0001C, 0x700038, 0x300030, 0x300030,0x700038,0xE0001C,0xC0000C};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='Y'){
		for(int t=0;t<h;t++){
	int Row[]= { 0x0, 0x1C, 0x38, 0xF00030, 0xF00030,0x38,0x1C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='Y'){
		for(int t=0;t<h;t++){
	int Row[]= { 0x0, 0x1C, 0x38, 0xF00030, 0xF00030,0x38,0x1C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}else if(n=='Z'){
		for(int t=0;t<h;t++){
	int Row[]= { 0x0, 0xE0000C,0xF0000C, 0xF0002C, 0xD0003C,0xC0003C,0xC0001C,0x0};
	int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};

			for(m=0;m<8;m++)
			{
				g=m+l;
				PTE->PCOR= Row[g];
				PTE->PSOR= ~Row[g];
				PTB->PSOR= Column[m];
				PTB->PCOR= ~Column[m];
				delayMs(1);

			}
	}
	}
	}
	int   character (char n,int z){


		if(n=='0'){

			int Row[]= {0x0,0x700038,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0x700038,0x0};
			return Row[z];
		}else if(n=='1'){

		int Row[]= {0x0,0x20,0x30,0x18,0xF0003C,0xF0003C,0x0,0x0};
		return Row[z];
		}else if(n=='2'){

		int Row[]= {0x0,0xC00018,0xE0001C,0xF0001C,0xF0002C,0xD0003C,0xC00038,0x0};

		return Row[z];
		}else if(n=='3'){

		int Row[]= {0x0,0x400008,0xC0000C,0xD0002C,0xD0002C,0xF0003C,0x700038,0x0};
		return Row[z];
		}else if(n=='4'){

		int Row[]= {0x0,0x10003C,0x10003C,0x100020,0x100020,0xF0003C,0xF0003C,0x0};
		return Row[z];
		}else if(n=='5'){
		int Row[]= {0x0,0x40003C,0xD0003C,0xD0002C,0xD0002C,0xF0002C,0x70000C,0x0};
		return Row[z];
		}else if(n=='6'){

		int Row[]= {0x0,0x700038,0xF0003C,0xD0002C,0xD0002C,0xF0002C,0x700004,0x0};
		return Row[z];
		}else if(n=='7'){

		int Row[]= {0x0,0x0,0xC,0xF0000C,0xF0002C,0x3C,0x1C,0x0};
		return Row[z];
		}else if(n=='8'){

		int Row[]= {0x0,0x600038,0xF0003C,0x90000C,0x90000C,0xF0003C,0x600038,0x0};
		return Row[z];
		}else if(n=='9'){

		int Row[]= {0x0,0x38,0x50003C,0x90000C,0x90000C,0xF0003C,0x700038,0x0};
		return Row[z];
		}else if(n=='A'){

		int Row[]= {0x0,0xF00038,0xF0003C,0x10000C,0x10000C,0xF0003C,0xF00038,0x0};
		return Row[z];
		}else if(n=='B'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x90000C,0x90000C,0xF0003C,0x700038,0x0};
		return Row[z];
		}else if(n=='C'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xC0000C,0xC0000C,0x0};
		return Row[z];
		}else if(n=='D'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0x700038,0x0};
		return Row[z];
		}else if(n=='E'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xD0002C,0xD0002C,0xD0002C,0xD0002C,0x0};
		return Row[z];
		}else if(n=='F'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x10002C,0x10002C,0x10002C,0x10002C,0x0};
		return Row[z];
		}else if(n=='G'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xD0002C,0xF0002C,0xF0002C,0x0};
		return Row[z];
		}else if(n=='H'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x100020,0x100020,0xF0003C,0xF0003C,0x0};
		return Row[z];
		}else if(n=='I'){

		int Row[]= {0x0,0x0,0x0,0xF0003C,0xF0003C,0x0,0x0,0x0};
		return Row[z];
		}else if(n=='J'){

		int Row[]= {0x0,0xF00000,0xF00000,0xC00000,0xC00000,0xF0003C,0xF0003C,0x0};
		return Row[z];
		}else if(n=='K'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x300030,0x700038,0xE0001C,0xC0000C,0x0};
		return Row[z];
		}else if(n=='L'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC00000,0xC00000,0xC00000,0xC00000,0x0};
		return Row[z];
		}else if(n=='M'){

		int Row[]= {0xF0003C,0xF0003C,0x18,0x30,0x30,0x18,0xF0003C,0xF0003C};
		return Row[z];
		}else if(n=='N'){

		int Row[]= {0xF0003C,0xF0003C,0x38,0x100030,0x300020,0x700000,0xF0003C,0xF0003C};
		return Row[z];
		}else if(n=='O'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0xF0003C,0x0};
		return Row[z];
		}else if(n=='P'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x10000C,0x10000C,0x10003C,0X10003C,0x0};
		return Row[z];
		}else if(n=='Q'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC0000C,0xC0000C,0xF0003C,0xF0003C,0xC00000};
		return Row[z];
		}else if(n=='R'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0x30000C,0x70000C,0xD0003C,0x800038,0x0};
		return Row[z];
		}else if(n=='R'){

		int Row[]= {0x0,0x400038,0xC0003C,0xD0002C,0xD0002C,0xF0002C,0x700008,0x0};
		return Row[z];
		}else if(n=='T'){

		int Row[]= {0x0,0xC,0xC,0xF0003C,0xF0003C,0xC,0xC,0x0};
		return Row[z];
		}else if(n=='U'){

		int Row[]= {0x0,0xF0003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0xF0003C,0x0};
		return Row[z];
		}else if(n=='V'){

		int Row[]= {0x0,0x70003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0x70003C,0x0};
		return Row[z];
		}else if(n=='V'){

		int Row[]= {0x0,0x70003C,0xF0003C,0xC00000,0xC00000,0xF0003C,0x70003C,0x0};
		return Row[z];
		}else if(n=='W'){

		int Row[]= {0xF0003C,0xF0003C,0x600000,0x300000,0x300000,0x600000,0xF0003C,0xF0003C};
		return Row[z];
		}else if(n=='X'){

		int Row[]= { 0xC0000C, 0xE0001C, 0x700038, 0x300030, 0x300030,0x700038,0xE0001C,0xC0000C};
		return Row[z];
		}else if(n=='Y'){

		int Row[]= { 0x0, 0x1C, 0x38, 0xF00030, 0xF00030,0x38,0x1C,0x0};
		return Row[z];
		}else if(n=='Y'){

		int Row[]= { 0x0, 0x1C, 0x38, 0xF00030, 0xF00030,0x38,0x1C,0x0};
		return Row[z];
		}else if(n=='Z'){

		int Row[]= { 0x0, 0xE0000C,0xF0000C, 0xF0002C, 0xD0003C,0xC0003C,0xC0001C,0x0};
		return Row[z];
		}else if(n==' '){

			int Row[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
			return Row[z];
			}else{ return 0;}



	}
	void Matrixscrollleft(char c[32]){
		int l,m,n,j,k,g;
		//void LCD_Write(char c[32])
		int fila[8];
			int i=0;
			for(i=0;c[i] !='\0'; i++)
			{
				for(int t=0;t<8;t++){
			fila[t]=character(c[i],t);
			}
			int Row2[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0};
			int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800,0x0,0x0};
			for(int t=0;t<8;t++){
				Row2[t+8]=fila[t];
			}
			for (l=0;l<16;l++){
				for(n=0;n<3;n++){
					for(m=0;m<8;m++)
					{
						g=m+l;
						PTE->PCOR= Row2[g];
						PTE->PSOR= ~Row2[g];
						PTB->PSOR= Column[m];
						PTB->PCOR= ~Column[m];
						delayMs(1);

					}
				}
			}

			}


	}
	void Matrixscrollrigth(char c[32]){
		int l,m,n,j,k,g;
		//void LCD_Write(char c[32])
		int fila[8];
			int i=0;
			for(i=0;c[i] !='\0'; i++)
			{
				for(int t=0;t<8;t++){
			fila[t]=character(c[i],t);
			}
			int Row2[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0};
			int Column[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};
			for(int t=0;t<8;t++){
				Row2[t+8]=fila[t];
			}
			for (l=15;l>0;l--){
				for(n=0;n<3;n++){
					for(m=0;m<8;m++)
					{
						g=m+l;
						PTE->PCOR= Row2[g];
						PTE->PSOR= ~Row2[g];
						PTB->PSOR= Column[m];
						PTB->PCOR= ~Column[m];
						delayMs(1);

					}
				}
			}

			}


	}

	int   character2 (char n,int z){


	if(n=='0'){

	int Row[]= {0x0,0x30C,0x606,0x60E,0x706,0x606,0x606,0x30C};
	return Row[z];
	}else if(n=='1'){

	int Row[]= {0x0,0x108,0x108,0x10C,0x108,0x108,0x108,0x70E};
	return Row[z];
	}else if(n=='2'){

	int Row[]= {0x0,0x30C,0x606,0x600,0x300,0xC,0x6,0x70E};

	return Row[z];
	}else if(n=='3'){

	int Row[]= {0x0,0x30C,0x606,0x300,0x308,0x600,0x606,0x30C};
	return Row[z];
	}else if(n=='4'){

	int Row[]= {0x0,0x300,0x308,0x304,0x302,0x70E,0x300,0x300};
	return Row[z];
	}else if(n=='5'){
	int Row[]= {0x0,0x70E,0x6,0x30E,0x600,0x600,0x606,0x30C};
	return Row[z];
	}else if(n=='6'){

	int Row[]= {0x0,0x30C,0x606,0x6,0x30E,0x606,0x606,0x30C};
	return Row[z];
	}else if(n=='7'){

	int Row[]= {0x0,0x70E,0x606,0x300,0x300,0x108,0x108,0x108};
	return Row[z];
	}else if(n=='8'){

	int Row[]= {0x0,0x30C,0x606,0x606,0x30C,0x606,0x606,0x30C};
	return Row[z];
	}else if(n=='9'){

	int Row[]= {0x0,0x30C,0x606,0x606,0x70C,0x600,0x606,0x30C};
	return Row[z];
	}else if(n=='A'){

	int Row[]= {0x0,0x30C,0x606,0x606,0x70E,0x606,0x606,0x606};
	return Row[z];
	}else if(n=='B'){

	int Row[]= {0x0,0x30E,0x606,0x606,0x30E,0x606,0x606,0x30E};
	return Row[z];
	}else if(n=='C'){

	int Row[]= {0x0,0x30C,0x606,0x6,0x6,0x6,0x606,0x30C};
	return Row[z];
	}else if(n=='D'){

	int Row[]= {0x0,0x30E,0x606,0x606,0x606,0x606,0x606,0x30E};
	return Row[z];
	}else if(n=='E'){

	int Row[]= {0x0,0x70E,0x6,0x6,0x30E,0x6,0x6,0x70E};
	return Row[z];
	}else if(n=='F'){

	int Row[]= {0x0,0x70E,0x6,0x6,0x30E,0x6,0x6,0x6};
	return Row[z];
	}else if(n=='G'){

	int Row[]= {0x0,0x30C,0x606,0x6,0x6,0x706,0x606,0x30C};
	return Row[z];
	}else if(n=='H'){

	int Row[]= {0x0,0x606,0x606,0x606,0x70E,0x606,0x606,0x606};
	return Row[z];
	}else if(n=='I'){

	int Row[]= {0x0,0x30C,0x108,0x108,0x108,0x108,0x108,0x30C};
	return Row[z];
	}else if(n=='J'){

	int Row[]= {0x0,0x708,0x300,0x300,0x300,0x306,0x306,0x10C};
	return Row[z];
	}else if(n=='K'){

	int Row[]= {0x0,0x606,0x306,0x10E,0xE,0x10E,0x306,0x606};
	return Row[z];
	}else if(n=='L'){

	int Row[]= {0x0,0x6,0x6,0x6,0x6,0x6,0x6,0x70E};
	return Row[z];
	}else if(n=='M'){

	int Row[]= {0x0,0xC06,0xE0E,0xF0E,0xD06,0xC06,0xC06,0xC06};
	return Row[z];
	}else if(n=='N'){

	int Row[]= {0x0,0xC06,0xC0E,0xD0E,0xF06,0xE06,0xC06,0xC06};
	return Row[z];
	}else if(n=='O'){

	int Row[]= {0x0,0x30C,0x606,0x606,0x606,0x606,0x606,0x30C};
	return Row[z];
	}else if(n=='P'){

	int Row[]= {0x0,0x30E,0x606,0x606,0x606,0x30E,0x6,0x6};
	return Row[z];
	}else if(n=='Q'){

	int Row[]= {0x0,0x30C,0x606,0x606,0x606,0x706,0x30C,0x600};
	return Row[z];
	}else if(n=='R'){

	int Row[]= {0x0,0x30E,0x606,0x606,0x30E,0x10E,0x306,0x606};
	return Row[z];
	}else if(n=='S'){

	int Row[]= {0x0,0x30C,0x606,0x6,0x30C,0x600,0x606,0x30C};
	return Row[z];
	}else if(n=='T'){

	int Row[]= {0x0,0x70E,0x50A,0x108,0x108,0x108,0x108,0x108};
	return Row[z];
	}else if(n=='U'){

	int Row[]= {0x0,0x606,0x606,0x606,0x606,0x606,0x606,0x70C};
	return Row[z];
	}else if(n=='V'){

	int Row[]= {0x0,0x606,0x606,0x606,0x606,0x606,0x30C,0x108};
	return Row[z];
	}else if(n=='V'){

	int Row[]= {0x0,0x606,0x606,0x606,0x606,0x606,0x30C,0x108};
	return Row[z];
	}else if(n=='W'){

	int Row[]= {0x0,0xC06,0xC06,0xC06,0xD06,0xF0E,0xE0E,0xC06};
	return Row[z];
	}else if(n=='X'){

	int Row[]= { 0x0, 0xC06, 0xC06, 0x60C, 0x308,0x60C,0xC06,0xC06};
	return Row[z];
	}else if(n=='Y'){

	int Row[]= { 0x0, 0x606, 0x606, 0x606, 0x30C,0x108,0x108,0x108};
	return Row[z];
	}else if(n=='Y'){

	int Row[]= { 0x0, 0x606, 0x606, 0x606, 0x30C,0x108,0x108,0x108};
	return Row[z];
	}else if(n=='Z'){

	int Row[]= { 0x0, 0x70E,0x600, 0x300, 0x108,0xC,0x6,0x70E};
	return Row[z];
	}else if(n==' '){

	int Row[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
	return Row[z];
	}else{ return 0;}



	}
	void Matrixscrollup(char c[32]){
		int l,m,n,j,k,g;
	//void LCD_Write(char c[32])
	int fila[8];
	int i=0;
	for(i=0;c[i] !='\0'; i++)
	{
	for(int t=0;t<8;t++){
	fila[t]=character2(c[i],t);
	}


	int Row2[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0};
	int Column[]= {0x04,0x08,0x10,0x20,0x100000,0x200000,0x400000,0x800000};
	for(int t=0;t<8;t++){
	Row2[t+8]=fila[t];
	}
	for (l=0;l<16;l++){
	for(n=0;n<3;n++){
	for(m=0;m<8;m++)
	{
	g=m+l;
	PTB->PSOR= Row2[g];
	PTB->PCOR= ~Row2[g];
	PTE->PCOR= Column[m];
	PTE->PSOR= ~Column[m];

	delayMs(1);

	}
	}
	}
	}
	}

	void Matrixscrolldown(char c[32]){
		int l,m,n,j,k,g;

		//void LCD_Write(char c[32])
		int fila[8];
		int i=0;
		for(i=0;c[i] !='\0'; i++)
		{
		for(int t=0;t<8;t++){
		fila[t]=character2(c[i],t);
		}


		int Row2[]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0, 0x0,0x0,0x0,0x0,0x0};
		int Column[]= {0x04,0x08,0x10,0x20,0x100000,0x200000,0x400000,0x800000};
		for(int t=0;t<8;t++){
		Row2[t+8]=fila[t];
		}
		for (l=15;l>0;l--){
		for(n=0;n<3;n++){
		for(m=0;m<8;m++)
		{
		g=m+l;
		PTB->PSOR= Row2[g];
		PTB->PCOR= ~Row2[g];
		PTE->PCOR= Column[m];
		PTE->PSOR= ~Column[m];

		delayMs(1);

		}
		}
		}
		}
		}
	void MatrixDraw(int matrix[][8])

	{
		int l,m,n,j,k,g,i;

		for(n = 0; n < 50; n++ )
		{
			for(j = 0; j < 8; j++)
				{
					for(i = 0; i < 8; i++)
					{
						if(matrix[i][j] == 1)
							set_pin(i,j);
					//	printf ("\n %u", matrix[i][j]);
					}

				}
		}

	}
	void set_pin(int i, int j)
	{
		int Column[]= {0x04,0x08,0x10,0x20,0x100000,0x200000,0x400000,0x800000};
		int row[]= {0x01,0x02,0x04,0x08,0x100,0x200,0x400,0x800};
		PTE->PCOR =  Column[i];
		PTE->PSOR =  ~Column[i];
		PTB->PSOR =row[j];
		PTB->PCOR =  ~row[j];
		delayUs(1);
	}
