#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#include "HDM64GS12_scanbang.c"
#include "C:\Program Files\PICC\Drivers\graphics.c"
#include "C:\Program Files\PICC\Drivers\math.h"
#include "24256.c"
int m;
float SensorY0, SensorY1, SensorY2, SensorY3, SensorY4, SensorY5, SensorY6, SensorY7;
char CharY0[5] = "0.0";
char CharY1[5] = "0.0";
char CharY2[5] = "0.0";
char CharY3[5] = "0.0";
short int dbutton4, dbutton5, dbutton6, dbutton7;
float read_analog(int a);
void start(){
char Empresa[10] = "PRESENTACION";
char Desc[16] = "bla bla";
glcd_text57(0, 0, Empresa, 2, ON);
glcd_text57(0, 20, Desc, 2, ON);
}
void Pantalla_1(){
extern float SensorY0, SensorY1, SensorY2, SensorY3, SensorY4, SensorY5, SensorY6, SensorY7;
extern float read_analog(int a);
extern char CharY0[];
extern char CharY1[];
extern char CharY2[];
extern char CharY3[];
char TempEXT[20] = "Temp. Externa:";
char TempMOT[20] = "Temp. Motor:";
char TempALT[20] = "Temp. Alternad:";
char TempINT[20] = "Temp. Interna:";
glcd_text57(0, 10, TempEXT, 1, ON);
glcd_text57(0, 20, TempMOT, 1, ON);
glcd_text57(0, 30, TempALT, 1, ON);
glcd_text57(0, 40, TempINT, 1, ON);
SensorY0 = read_analog(0) * (5.0 * 100.0 / 1024.0);
SensorY1 = read_analog(1) * (5.0 * 100.0 / 1024.0);
SensorY2 = read_analog(2) * (5.0 * 100.0 / 1024.0);
SensorY3 = read_analog(3) * (5.0 * 100.0 / 1024.0);
glcd_text57(95, 10, CharY0, 1, OFF);
glcd_text57(95, 10, CharY0, 1, ON);
glcd_text57(95, 20, CharY1, 1, OFF);
glcd_text57(95, 20, CharY1, 1, ON);
glcd_text57(95, 30, CharY2, 1, OFF);
glcd_text57(95, 30, CharY2, 1, ON);
glcd_text57(95, 40, CharY3, 1, OFF);
glcd_text57(95, 40, CharY3, 1, ON);
}
int menu(int p){
char Menu[27] = "TEMP | GRUPO | MONIT | --";
if (p == 0){
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_line(0,63,30,63,ON);
glcd_text57(0, 55, Menu, 1, OFF);
return(0);
}
if (p == 1){
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_line(30,63,70,63,ON);
glcd_text57(0, 55, Menu, 1, OFF);
return(1);
}
if (p == 10){
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_line(70,63,110,63,ON);
glcd_text57(0, 55, Menu, 1, OFF);
return(10);
}
}
float read_analog(int a)
{
float ADC_Value;
if (a == 0){
output_low(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
}
if (a == 1){
output_high(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
}
if (a == 2){
output_low(PIN_A1);
output_high(PIN_A2);
output_low(PIN_A3);
}
if (a == 3){
output_high(PIN_A1);
output_high(PIN_A2);
output_low(PIN_A3);
}
if (a == 4){
output_low(PIN_A1);
output_low(PIN_A2);
output_high(PIN_A3);
}
if (a == 5){
output_high(PIN_A1);
output_low(PIN_A2);
output_high(PIN_A3);
}
if (a == 6){
output_low(PIN_A1);
output_high(PIN_A2);
output_high(PIN_A3);
}
if (a == 7){
output_high(PIN_A1);
output_high(PIN_A2);
output_high(PIN_A3);
}
delay_ms(100);
set_adc_channel (0); //Elige canal a medir RA0
delay_us (20);
ADC_Value=read_adc(); //Capturamos señal analógica que entra por el canal previamente seleccionado (RA0)
return(ADC_Value);
}
#int_rb
void test_detect_rb_change() {
set_tris_b(0xF0);
//current=input_b();
if (input(PIN_B4)) {dbutton4=1;}
else {dbutton4=0;}
}
void clear_delta() {
dbutton4=0;
dbutton5=0;
dbutton6=0;
dbutton7=0;
}
void main(void)
{
m = 0;
clear_delta();
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
glcd_init(ON); // iniciamos la lcd
glcd_fillScreen(OFF); //LIMPIAMOS LA PANTALLA
delay_ms(100);
start();
delay_ms(2000);
glcd_fillScreen(OFF); //LIMPIAMOS LA PANTALLA
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_a(0xEF);
while (TRUE)
{
if(dbutton4) {
delay_ms(15);
if(dbutton4) {
if (m == 1) {m = menu(10);}
else if (m == 10) {m = menu(0);}
else
m = menu(1);
}
}
else if(!dbutton4){
delay_ms(20);
if(!dbutton4) {
//printf("nothing");
}
}
delay_ms(100);
Pantalla_1();
}
}