Menu en Pantalla

Este es una practica muy sencilla del cual consta de aparecer un MENU en un GLCD.

qzf1jk.jpg


Código:
//CONFIGURACION///////////////////
#include<16F886.h>
#include<stdio.h>
#fuses HS,NOWDT,NOPUT,MCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,FCMEN,NOLVP,NODEBUG
#use delay(clock=20000000)
#use standard_io(c)

#define GLCD_CS1 PIN_B2   // Chip Selection 1
#define GLCD_CS2 PIN_B3   // Chip Selection 2
#define GLCD_DI  PIN_B4   // Data or Instruction input
#define GLCD_RW  PIN_B5   // Read/Write
#define GLCD_E   PIN_B6   // Enable
#define GLCD_RST PIN_B7   // Reset
#include<GLCD.C>

char buff[25];
unsigned char y;
const char txt[][25]={"> STATUS OUTPUTS","> STATUS INPUTS","> STATUS PWM SERVOS","> STATUS DISTANCE",
					  "> MOVE SERVOS MANUAL","> CONFIG. SPEED","> CONFIG. DISTANCE","> ABOUT"};
const char out[]={"BACK"};
unsigned char out_in[9];

/////////////////////////////////////
//MUESTRA EL CONTENIDO DEL MENU
/////////////////////////////////////
void MENU(void){
	glcd_fillscreen(OFF);
	for(y=0;y<8;y++){
		sprintf(buff,"%s",txt[y]);
		glcd_text57(1,y*8,&buff,1,ON);
	}
}
/////////////////////////////////////
//OBTIENE TAMANO DE TEXTO DEL ARREGLO
/////////////////////////////////////
int CLEAR_PUT_AUX(int v){
	int vv=0;
	while(txt[v][vv]!=0){
		vv++;
	}
	return ++vv;
}
///////////////////////////////////
//PONE TEXTO ANTERIOR PARA
//RESTABLECERLO
///////////////////////////////////
void PUT_TEXT(int yy,int txtlen){
	glcd_rect(1,(yy*8),(txtlen*5)+13,(yy*8)+7,ON,OFF);
	sprintf(buff,"%s",txt[yy]);
	glcd_text57(1,(yy*8),&buff,1,ON);	
}
///////////////////////////////////
//SELECTOR DE OPCIONES
///////////////////////////////////
int SELECTOR(){
	signed int sel=0;
	
	while(TRUE){
		if(input(PIN_A0)==1 || input(PIN_A1)==1){
			if(input(PIN_A0)){
				PUT_TEXT(sel,CLEAR_PUT_AUX(sel));
				sel++;
				if(sel>=8)sel=8;
			}else if(input(PIN_A1)){
				PUT_TEXT(sel,CLEAR_PUT_AUX(sel));
				sel--;	
				if(sel<=0)sel=0;
			}
			
			glcd_rect(1,(sel*8),(CLEAR_PUT_AUX(sel)*5)+13,(sel*8)+7,ON,ON);
			sprintf(buff,"%s",txt[sel]);
			glcd_text57(1,(sel*8),&buff,1,OFF);
			delay_ms(300);
		}
		if(input(PIN_A2)==1){
			break;
		}
	}
	return sel;
}
//////////////////////////////
//VISUALIZA "SALIR"
//////////////////////////////
void back(void){
	glcd_rect(48,54,75,63,ON,ON);
	sprintf(buff,"%s",out);
	glcd_text57(49,55,&buff,1,OFF);
}
//////////////////////////////
//SACA LOS BINARIOS DE LAS SALIDAS & ENTRADAS
//A CARACTERES
//////////////////////////////
void BIN_C(unsigned int data){
	unsigned int yy=0;
	
	for(yy=0;yy<8;yy++){
		if((data&0x01)==1)
			out_in[yy]='1';
		else
			out_in[yy]='0';
		data>>=1;
	}
}
//////////////////////////////
//STATUS SALIDA
//////////////////////////////
void STATUS_SALIDA(void){
	int p=0;
	sprintf(buff,"%s",txt[0]);
	glcd_text57(1,1,&buff,1,ON);
	back();
	while(TRUE){	
		BIN_C(p);
		p++;
		sprintf(buff,"%s",out_in);
		glcd_rect(15,20,120,35,ON,OFF);
		glcd_text57(15,21,&buff,2,ON);
		delay_ms(500);
		if(input(PIN_A0)==1)break;
	}
}
/////////////////////////////
//STATUS ENTRADAS
/////////////////////////////
void STATUS_ENTRADA(void){
	
}
////////////////////////////
//MENU PRINCIPAL
////////////////////////////
void main(void){
	int target;
	set_tris_a(0x07);
	setup_adc(ADC_OFF);						//CONVERTIDOR ANALOGO-DIGITAL APAGADO
	setup_comparator(NC_NC_NC_NC);			//Comparadores APAGADO
	
	glcd_init(ON);
	
	while(TRUE){
		MENU();
		target=SELECTOR();
		glcd_fillscreen(OFF);
		if(target==0)STATUS_SALIDA();
	}
}

 

Adjuntos

  • LibGLCD.zip
    64.1 KB · Visitas: 28
Última edición por un moderador:
Aja...todo bien...y?

Esto es un aporte?
O necesitas preguntar algo?
O querés hacerlo?
O tiene algún error la programación?...

Si es aporte, muy bueno (y)
 
No se pero con esto de los compiladores C con librerias incluidas como que hace mas facil esta clase de tareas, algo interesante es hacer todo uno mismo ahi si que da dolores de cabeza pero se quita cuando ves que la cosa funciona, tengo instalado el avr studio y el mikro avr este ultimo es bueno cuando quieres hacer algo rapido pero cuando tienes que poner atencion a detalles pequeños mejor uso avr studio.

Pero volviendo al tema que fue este mensaje porque no entendi sobre todo por el titulo
 
Atrás
Arriba