Revision: 66309
Updated Code
at April 19, 2014 06:20 by eiger_824
Updated Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; while(b!=0){ int i; c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espa�ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el C�DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255� almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero b=1; aux1=0; dinero=0; do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero>10000){ Glcd_Fill(0); Glcd_LineaROM("Max.:10000",1); for (j=0; j<i; j++) { aux[j] = 0;} delay_ms(1000); Glcd_Fill(0); } }while(dinero>10000); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); } else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero>10000){ Glcd_Fill(0); Glcd_LineaRAM("Max.:10000",1); for (j=0; j<i; j++){ aux[j] = 0;} delay_ms(1000); Glcd_Fill(0); } }while(dinero>10000); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("No coinciden.",1); else Glcd_LineaROM("Not the same.",1); Delay_ms(1000); Glcd_Fill(0); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(900); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Revision: 66308
Updated Code
at April 16, 2014 21:15 by eiger_824
Updated Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; char output[11] = {0}; while(b!=0){ int i; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espaÃ’ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el Câ€DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255Ä almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero b=1; aux1=0; dinero=0; do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero>10000){ Glcd_Fill(0); Glcd_LineaROM("Max.:10000",1); for (j=0; j<i; j++) { aux[j] = 0;} delay_ms(1000); Glcd_Fill(0); } }while(dinero>10000); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); } else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero>10000){ Glcd_Fill(0); Glcd_LineaRAM("Max.:10000",1); for (j=0; j<i; j++){ aux[j] = 0;} delay_ms(1000); Glcd_Fill(0); } }while(dinero>10000); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("No coinciden.",1); else Glcd_LineaROM("Not the same.",1); Delay_ms(1000); Glcd_Fill(0); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(900); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Revision: 66307
Updated Code
at April 15, 2014 21:21 by eiger_824
Updated Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; char output[11] = {0}; while(b!=0){ int i; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir���· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espa���ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el C�¢ï¿½ï¿½DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255��� almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); }else if(dinero > 10000){ if(idioma==1)Glcd_LineaRAM("Cant. maxima 10000",2); else Glcd_LineaRAM("Max. amount 10000",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ if(idioma==1)Glcd_LineaROM("No coinciden.",3); else Glcd_LineaROM("Not the same.",3); Delay_ms(1000); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(500); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Revision: 66306
Updated Code
at April 15, 2014 21:19 by eiger_824
Updated Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; char output[11] = {0}; while(b!=0){ int i; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir�· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espa��ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el Câ��DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255�� almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); }else if(dinero > 10000){ if(idioma==1)Glcd_LineaRAM("Cant. maxima 10000",2); else Glcd_LineaRAM("Max. amount 10000",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ if(idioma==1)Glcd_LineaROM("No coinciden.",3); else Glcd_LineaROM("Not the same.",3); Delay_ms(1000); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(500); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Revision: 66305
Updated Code
at April 15, 2014 21:18 by eiger_824
Updated Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; char output[11] = {0}; while(b!=0){ int i; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espa�ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el C�DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255� almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); }else if(dinero > 10000){ if(idioma==1)Glcd_LineaRAM("Cant. maxima 10000",2); else Glcd_LineaRAM("Max. amount 10000",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ if(idioma==1)Glcd_LineaROM("No coinciden.",3); else Glcd_LineaROM("Not the same.",3); Delay_ms(1000); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(500); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Revision: 66304
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 15, 2014 21:12 by eiger_824
Initial Code
/* * Project name: ATM_OS * Test configuration: MCU: PIC18F45K20 Dev.Board: EasyLV18F v6 Oscillator: HS, 08.0000 MHz SW: mikroC PRO */ char keypadPort at PORTD; //glcd inicializacion char GLCD_DataPort at PORTD; sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS2 at RB1_bit; sbit GLCD_RS at RB2_bit; sbit GLCD_RW at RB3_bit; sbit GLCD_EN at RB4_bit; sbit GLCD_RST at RB5_bit; sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections const unsigned short TEMP_RESOLUTION = 9; char *text = "00.0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (temp_whole/100) text[0] = temp_whole/100 + 48; else text[0] = (temp_whole/10)%10 + 48; // Extract tens digit text[1] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[3] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(1, 7, text); } void Tone1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono1(){ Sound_Play(440, 75); Delay_ms(75); } void Tono2(){ Sound_Play(400, 75); Delay_ms(75); } void Tono3(){ Sound_Play(340, 75); Delay_ms(75); } void Tono4(){ Sound_Play(274, 75); Delay_ms(75); } void Tono5(){ Sound_Play(458, 75); Delay_ms(75); } void Tone2(){ Sound_Play(476, 75); Delay_ms(75); } void Tone3(){ Sound_Play(548, 75); Delay_ms(75); } void Tone4(){ Sound_Play(476, 500); } void Tone5(){ Sound_Play(440, 500); } void Tone6(){ Sound_Play(548, 500); } void Gasolina(){ Sound_Init(&PORTC,2); Tone1(); Tone1(); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone1(); Delay_ms(125); Tone4(); Tone5(); Tone2(); Tone2(); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone2(); Delay_ms(125); Tone6(); Tone4(); Glcd_Init(); } void Animals(){ Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono3();delay_ms(75);Tono3();Tono4();delay_ms(150);Tono4(); Tono1(); Tono1(); Tono1(); Tono1();Tono2();Tono2();delay_ms(75);Tono2();Tono5();delay_ms(75);Tono1(); Glcd_Init(); } void Glcd_LineaRAM(char* miLinea, int linea){ Glcd_Write_Text(miLinea, 5, linea, 1); } void String_ROM2RAM(char *RAM, const char *ROM) { unsigned short i = 0; // Mientras haya datos en el string ROM while (ROM[i]) { // Copiar de ROM a RAM RAM[i] = ROM[i]; // Aumentar el puntero del string i++; } // Meter caracter nulo / fin de string RAM[i]=0; } void Glcd_LineaROM(const char* StringROM, int linea){ char StringRAM[40]; String_ROM2RAM(StringRAM, StringROM); Glcd_Write_Text(StringRAM, 5, linea, 1); } int Num_Selec(void){ int res; char kp; Sound_Init(&PORTC,2); Keypad_Init(); //Puerto D (KEYPAD 4X4) como entrada do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); switch(kp){ case 1: res=1; break; // 1 // Uncomment this block for keypad4x4 case 2: res=2; break; // 2 case 3: res=3; break; // 3 case 4: res=10; break; // A case 5: res=4; break; // 4 case 6: res=5; break; // 5 case 7: res=6; break; // 6 case 8: res=20; break; // B case 9: res=7; break; // 7 case 10: res=8; break; // 8 case 11: res=9; break; // 9 case 12: res=20; break; // C case 13: res=20; break; // * case 14: res=0; break; // 0 case 15: res=20; break; // # case 16: res=20; break; // D } Sound_Play(880, 200); Glcd_Init(); //Puerto D (KEYPAD 4X4) como salida return res; } void PedirPin(int lang){ int b = 3; int c; int pin = 0; char output[11] = {0}; while(b!=0){ int i; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros c=0; pin=0; Glcd_Fill(0); if (lang==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ Glcd_Fill(0); if (lang==1)Glcd_LineaROM(" Bienvenido.. ",3); else Glcd_LineaROM(" Welcome.. ",3); Gasolina(); break;//sale del bucle } else{ if(lang==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Wrong PIN",3); b=b-1; if (b==2){ if (lang==1)Glcd_LineaROM("2 restantes",4); else Glcd_LineaROM("2 left",4); } else if (b==1){ if (lang==1)Glcd_LineaROM("1 restante",4); else Glcd_LineaROM("1 left",4); } Sound_Play(220, 1000); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(lang==1) Glcd_LineaROM(" Acceso denegado",3); else Glcd_LineaROM(" Unauthorized access",3); Sound_Play(100, 3000); return; //Se acaba el programa return; } } const int PedirIdioma(void){ int ok=1; int idioma; while(ok==1){ Glcd_LineaROM("***IDIOMA/LANGUAGE***",2); Glcd_LineaROM("1. Espanol",3); Glcd_LineaROM("2. English",4); idioma=Num_Selec(); Glcd_Init(); if(idioma==1 || idioma==2){ ok=0; return idioma; } else{ GLCD_LineaROM("Elija bien el idioma.",4); Delay_ms(1000); Glcd_Fill(0); } } } int Menu(int lang){ int opc; Glcd_Fill(0); if(lang==1){ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Consultar saldo",2); Glcd_LineaROM("2. Sacar dinero",3); Glcd_LineaROM("3. Meter dinero",4); Glcd_LineaROM("4. Cambiar PIN",5); Glcd_LineaROM("5. Recargar movil",6); Glcd_LineaROM("6. Salir",7); opc=Num_Selec(); return opc; }else{ Glcd_LineaROM(" ***MENU***",1); Glcd_LineaROM("1. Check money",2); Glcd_LineaROM("2. Withdraw",3); Glcd_LineaROM("3. Deposit",4); Glcd_LineaROM("4. Change PIN",5); Glcd_LineaROM("5. Charge phone",6); Glcd_LineaROM("6. Exit",7); opc=Num_Selec(); return opc; } } void main() { //------------------------------------------INICIALIZACIONES--------------------------------------------------- int pin=0, newpin=0, newpin2=0; //Variable que ir· almacenando el PIN introducido por el usuario //short saldo; char *aux=""; int variable; int vector_variables[4]; int j,h; //char *output2; long aux1; int b=3; int c; //int contador; char output[11] = {0}; char dinero2[7]; //char carac; unsigned long movil; char cad[4]={0}; const code char logo_tecnun[1024] = { // GLCD Picture name: logo_tecnun.bmp 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 254, 255, 255, 255, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 0, 0, 0, 128, 192, 192, 192, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 255, 255, 255, 1, 1, 1, 1, 1, 1, 0, 240, 252, 255, 255, 119, 115, 113, 113, 97, 97, 115, 119, 127, 127, 126, 120, 0, 128, 248, 254, 255, 255, 159, 3, 1, 1, 1, 1, 3, 15, 31, 31, 31, 30, 0, 0, 0, 255, 255, 255, 255, 62, 15, 7, 3, 3, 3, 3, 15, 255, 255, 255, 254, 0, 0, 0, 0, 0, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 128, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 254, 31, 7, 3, 3, 3, 3, 7, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 15, 127, 255, 255, 248, 224, 192, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 63, 255, 255, 255, 248, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 31, 0, 0, 0, 0, 127, 255, 255, 255, 224, 128, 128, 128, 128, 128, 224, 248, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 7, 3, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 2, 0, 0, 0, 0, 0, 1, 3, 7, 7, 7, 7, 7, 7, 3, 3, 1, 3, 7, 7, 7, 3, 0, 0, 0, 0, 3, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int opc; int idioma; //1 para espaÃ’ol, 2 para ingles int ok=1, i=0; long dinero=0, dincaja=0; int var; var=EEPROM_Read(0x55); C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Sound_Init(&PORTC,2); ANSEL = 0x00; // Configure AN pins as digital ANSELH = 0; TRISA = 0x00; TRISC = 0; TRISB = 0x00; //Glcd inicializacion Glcd_Init(); Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32); Glcd_Fill(0); if(var!=0){ EEPROM_Write(0x02,1); //Guardamos el Câ€DIGO PIN 1234 en las direcciones 2,3,4 y 5 de memoria de la EEPROM EEPROM_Write(0x03,2); EEPROM_Write(0x04,3); EEPROM_Write(0x05,4); EEPROM_Write(0x11,200); //Saldo inicial en la cuenta = 255Ä almacenados en la EEPROM @ 0x11 EEPROM_Write(0x12,0); EEPROM_Write(0x13,0); EEPROM_Write(0x55,0); } //-------------------------------FIN INICIALIZACIONES--------------------------------------------------------------- //-----------------------------TEMPERATURA-------------------------------------------------------------------------- Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, "Temp.:"); // Print degree character, 'C' for Centigrades Lcd_Chr(1,11,178); Lcd_Chr(1,12,'C'); //--- Perform temperature reading Ow_Reset(&PORTC, 1); // Onewire reset signal Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0x44); // Issue command CONVERT_T Delay_us(120); Ow_Reset(&PORTC, 1); Ow_Write(&PORTC, 1, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 1, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 1); temp = (Ow_Read(&PORTC, 1) << 8) + temp; //--- Format and display result on Lcd Display_Temperature(temp); Glcd_Init(); //----------------------------------------------------------------------------------------------------------------- Glcd_Image(logo_tecnun); delay_ms(2000); Glcd_Fill(0); idioma = PedirIdioma(); PedirPin(idioma); while(1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros Glcd_Init(); opc = Menu(idioma); Glcd_Init(); if(opc==1){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros dinero = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dinero,dinero2); Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Saldo disponible:",1); else Glcd_LineaROM("Available money:",1); Glcd_LineaRAM(dinero2,2); Animals(); } else if(opc==2){ //Sacar dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a retirar: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to withdraw: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaRAM("No hay suficiente.",2); else Glcd_LineaRAM("Not enough funds.",2); delay_ms(2000); }else if(dinero > 10000){ if(idioma==1)Glcd_LineaRAM("Cant. maxima 10000",2); else Glcd_LineaRAM("Max. amount 10000",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Cantidad retirada.",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Amount withdrawn.",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } } else if(opc==3){ //meter dinero for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a meter: ",1); Glcd_LineaROM("(Cant. maxima: 10000)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to deposit: ",1); Glcd_LineaROM("(Max. amount: 10000)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1) Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); for(h=0;h<11;h++)output[h]=0; //volver a inicializar el vector 'output' do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; LongToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); dinero=aux1; //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); aux1 = dincaja+dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1)Glcd_LineaROM("Dinero en caja:",3); else Glcd_LineaROM("Available money;",3); dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); Glcd_Fill(0); } else if(opc==4){ c=0; b=3; pin=0; newpin=0; newpin2=0; i=0; while(b!=0){ char output[11] = {0}; c=0; pin=0; Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Insertar PIN: ",1); else Glcd_LineaROM("Insert PIN: ",1); for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaRAM("*",2); else if (i==1) Glcd_LineaRAM("**",2); else if (i==2) Glcd_LineaRAM("***",2); else if (i==3) Glcd_LineaRAM("****",2); if(pin==EEPROM_Read(0x02+i)) c++; } if(c==4){ break;//sale del bucle } else{ char output[11] = {0}; //Inicializar el vector de salida a ceros if(idioma==1)Glcd_LineaROM("PIN incorrecto",3); else Glcd_LineaROM("Incorrect PIN",3); b=b-1; IntToStr(b, output); if(idioma==1)strcat(output," restantes"); else strcat(output," left"); Glcd_LineaRAM(output,4); Delay_ms(1000); } } if(b==0){ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("Acceso denegado",3); else Glcd_LineaROM("Unauthorized access",3); Delay_ms(2000); break; } do{ Glcd_Fill(0); if(idioma==1)Glcd_LineaROM("PIN nuevo",1); else Glcd_LineaROM("New PIN",1); newpin=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",2); else if (i==1) Glcd_LineaROM("**",2); else if (i==2) Glcd_LineaROM("***",2); else if (i==3) Glcd_LineaROM("****",2); newpin= newpin*10; newpin=newpin + pin; } if(idioma==1)Glcd_LineaROM("De nuevo:",3); else Glcd_LineaROM("Again:",3); newpin2=0; for(i=0; i<4; i++){ pin=Num_Selec(); //Codigo para mostrar cuantos numeros se han escrito ya con circulillos if (i==0) Glcd_LineaROM("*",4); else if (i==1) Glcd_LineaROM("**",4); else if (i==2) Glcd_LineaROM("***",4); else if (i==3) Glcd_LineaROM("****",4); newpin2= newpin2*10; newpin2=newpin2 + pin; } if(newpin!=newpin2){ if(idioma==1)Glcd_LineaROM("No coinciden.",3); else Glcd_LineaROM("Not the same.",3); Delay_ms(1000); } }while (newpin!=newpin2); for(c=0; c<4; c++){ aux1= newpin % 10; EEPROM_Write(0x05-c,aux1); newpin=newpin/10; } Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("El PIN ha sido",1); Glcd_LineaROM(" cambiado",2); }else{ Glcd_LineaROM("PIN has been",1); Glcd_LineaROM(" changed.",2); } Delay_ms(1000); } else if(opc==5){ for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros b=1; aux1=0; dinero=0; //Pedir telefono Glcd_Fill(0); movil=0; if(idioma==1)Glcd_LineaROM("Numero de telefono: ",1); else Glcd_LineaROM("Phone number: ",1); for(i=0;i<9;i++){ variable=Num_Selec(); if(variable==10)break; else{ movil= movil*10; movil= movil + variable; LongToStr(movil,aux); Glcd_LineaRAM(aux,3); } } delay_ms(500); do{ Glcd_Fill(0); if(idioma==1) { Glcd_LineaROM("Cantidad a recargar: ",1); Glcd_LineaROM("(Multiplos de 5)" ,2); Glcd_LineaROM("Acepte con 'A'",3); }else{ Glcd_LineaROM("Money to charge: ",1); Glcd_LineaROM("(Integers of 5)" ,2); Glcd_LineaROM("Accept with 'A'",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); LongToStr(dincaja,dinero2); //strcat(disp,dinero2); if(idioma==1)Glcd_LineaROM("Disponible:",4); else Glcd_LineaROM("Available:",4); Glcd_LineaRAM(dinero2,5); aux1=0; i=0; do{ variable=Num_Selec(); if(variable==10)break; else{ vector_variables[i]= variable; IntToStr(variable,aux); aux1= aux1*10; aux1=aux1 + variable; IntToStr(aux1,aux); Glcd_LineaRAM(aux,6); i++; } } while(variable!=10); for (j=0; j<i; j++) aux[j] = 0; dinero=aux1; if(dinero%5!=0){ Glcd_Fill(0); if(idioma==1){ Glcd_LineaROM("Introduzca multiplos",1); Glcd_LineaROM("de 5 euros.",2); }else{ Glcd_LineaROM("Enter only",1); Glcd_LineaROM("integers of 5.",2); } delay_ms(2000); } }while (dinero%5!=0); //en este punto tengo un 'numero_final' que es el saldo que quiero retirar //ahora lo comparo con el saldo que tengo Glcd_Fill(0); if(dincaja<dinero){ if(idioma==1)Glcd_LineaROM("No hay suficiente.",2); else Glcd_LineaROM("Not enough funds.",2); delay_ms(2000); }else{//almacenar el entero dinero_en_caja en la memoria aux1 = dincaja-dinero; for (i=0; i<11; i++) output[i] = 0; //Inicializar el vector de salida a ceros LongToStr(aux1,output); dinero=aux1/16384; EEPROM_Write(0x13,dinero); aux1=aux1 % 16384; dinero=aux1/128; EEPROM_Write(0x12,dinero); aux1=aux1 % 128; EEPROM_Write(0x11, aux1); if(idioma==1){ Glcd_LineaROM("Movil cargado",2); Glcd_LineaROM("Disponible: ",3); }else{ Glcd_LineaROM("Phone charged",2); Glcd_LineaROM("Available: ",3); } dincaja = EEPROM_Read(0x13)*16384 + EEPROM_Read(0x12)*128 + EEPROM_Read(0x11); Glcd_LineaRAM(output,4); delay_ms(2000); } } else if(opc==6){ Sound_Init(&PORTC,2); if(idioma==1){ Glcd_Fill(0); Glcd_LineaROM("Muchas gracias por",1); Glcd_LineaROM("su visita, esperamos",2); Glcd_LineaROM("volver a verle pronto.",3); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM desarrollada por:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-Universidad",4); Glcd_LineaROM("De Navarra",5); Glcd_LineaROM("Abril 2014.",6); delay_ms(5000); Glcd_Fill(0); return; }else{ Glcd_Fill(0); Glcd_LineaROM("Thank you very much",1); Glcd_LineaROM("for your visit, we ",2); Glcd_LineaROM("hope to see you",3); Glcd_LineaROM("soon again.",4); Sound_Play(880,100); Sound_Play(1200,700); delay_ms(2000); Glcd_Fill(0); Glcd_LineaROM("ATM developed by:",1); Glcd_LineaROM("Oier Arroniz-903442",2); Glcd_LineaROM("Santi Pagola-903422",3); Glcd_LineaROM("Tecnun-University",4); Glcd_LineaROM("Of Navarre",5); Glcd_LineaROM("April 2014.",6); delay_ms(5000); Glcd_Fill(0); return; } } else{ if(idioma==1)Glcd_LineaROM("Elija bien la opcion", 6); else Glcd_LineaROM("Choose right option",6); Delay_ms(1000); } } }
Initial URL
Initial Description
Código final de la asignatura Microprocesadores y Microcontroladores de Tecnun - Universidad de Navarra (España). Curso 2013-2014. 3º IngenierÃa en Sistemas de Telecomunicación.
Initial Title
Programación en C de una ATM en un módulo GLCD con la placa de evaluación EasyLV18F
Initial Tags
c
Initial Language
C