Beispiel #1
0
void main(void) {
    int count;
    int size;
    unsigned int adcValue = 0;
    unsigned int adcValueOld = 0;
    char buffer[16];

    ConfigureOscillator();
    InitApp();

    lcd_init();
    lcd_enable();
    lcd_cursor_off();
    lcd_test();
    lcd_pos(2, 1);
    while (1) {
        ConvertADC();
        while (BusyADC());
        adcValue = ReadADC();
        if (adcValue != adcValueOld) {
            lcd_clear();
            //Linha 1
            lcd_pos(1, 1);
            memset(&buffer[0], 0, sizeof (buffer));
            sprintf(&buffer[0], "Step:%.4u %3.1f%%", adcValue, ((float) adcValue / 1023) * 100);
            size = (strlen(buffer) > sizeof(buffer)) ? sizeof(buffer) : strlen(buffer);
            lcd_write_buffer(buffer, size);
            for(count = 0; count < size; count++){
                while(BusyUSART());
                putcUSART((char)buffer[count]);
            }
            //Linha 2
            lcd_pos(2, 1);
            memset(&buffer[0], 0, sizeof (buffer));
            sprintf(&buffer[0], "Volts:%1.7fV", (float)adcValue * ((float)5 /1023));
            size = (strlen(buffer) > sizeof(buffer)) ? sizeof(buffer) : strlen(buffer);
            lcd_write_buffer(buffer, size);
            //Variável de controle
            adcValueOld = adcValue;
            for(count = 0; count < size; count++){
                while(BusyUSART());
                putcUSART((char)buffer[count]);
            }
        }
        for (count = 0; count < 40; count++) {
            __delay_ms(10);
        }
    }
}
void change_addr(){
    
    char key = 0;
    
    sprintf_P(lcd_buf_l1, PSTR("Select address"));
    sprintf_P(lcd_buf_l2, PSTR("1=MAC, 2=IP"));
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
    
    key = keypad_get_input();
    
    if(key == '1'){
        change_addr_mac();
        return;
    }
    
    if(key == '2'){
        change_addr_ip();
        return;
    }
    
    //Cancel
    if(key == 'C'){
        return;
    }
}
static inline void disp_addr(){
	
	sprintf_P(lcd_buf_l1, PSTR("%02x%02x%02x%02x%02x%02x"), _network_mac_addr[0], _network_mac_addr[1], _network_mac_addr[2], _network_mac_addr[3], _network_mac_addr[4], _network_mac_addr[5]);
	sprintf_P(lcd_buf_l2, PSTR("%d.%d.%d.%d"), _network_ip_addr[0], _network_ip_addr[1], _network_ip_addr[2], _network_ip_addr[3]);
	lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
	
}
void change_addr_mac(){
    
    char key = 0;
    
    sprintf_P(lcd_buf_l1, PSTR("New MAC"));
    sprintf_P(lcd_buf_l2, PSTR("%02x%02x%02x%02x%02x%02x"), _network_mac_addr[0], _network_mac_addr[1], _network_mac_addr[2], _network_mac_addr[3], _network_mac_addr[4], _network_mac_addr[5]);
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
    
    unsigned int idx = 0;
    do{
        key = keypad_get_input();   //Note that this is blockin function
        
        //TODO: implement a-f
        if((key >= '0') && (key <= '9')){
            
            lcd_buf_l2[idx++] = key;
            
            if(idx == 12){	//Stay on last character
                idx--;
            }
        }
        
        //Disp can be refreshed directly because keys are read with blocking function
        disp_refresh();
        
        //Cancel without changes
        if(key == 'C'){
            return;
        }
        
    }while(key != 'A');
    
    sscanf_P(lcd_buf_l2, PSTR("%2x%2x%2x%2x%2x%2x"), _network_mac_addr, _network_mac_addr+1, _network_mac_addr+2, _network_mac_addr+3, _network_mac_addr+4, _network_mac_addr+5);	//Read user given data
}
Beispiel #5
0
void main(void) {
    int count;
    unsigned int adcValue = 0;
    unsigned int adcValueOld = 0;
    char buffer[16];

    ConfigureOscillator();
    InitApp();

    lcd_init();
    lcd_enable();
    lcd_cursor_off();
    lcd_test();
    lcd_pos(2, 1);
    while (1) {
        ConvertADC();
        while (BusyADC());
        adcValue = ReadADC();
        if (adcValue != adcValueOld) {
            lcd_clear();
            lcd_pos(1, 1);
            memset(&buffer[0], 0, sizeof(buffer));
            sprintf(&buffer[0], "Valor: %.4u %.3u%%", adcValue, (int)(((float)adcValue / 1024) * 100));
            lcd_write_buffer(buffer, strlen(buffer));
            adcValueOld = adcValue;
        }
        __delay_ms(20);
    }
}
Beispiel #6
0
void interrupt high_isr(void){
   if((INTCONbits.INT0IF == 1) && (INTCONbits.INT0IE == 1)){
       lcd_clear();
       lcd_write_buffer("INTERRUPT INT0", 14);
       __delay_ms(20);
       INTCONbits.INT0IF = 0;
   }
}
static inline void disp_clock(){
	
	struct clockval cval;
	clock_get(&cval);
	struct timeval tval;
	time_get(&tval);
	sprintf_P(lcd_buf_l1, PSTR("Clock %02u:%02u:%02u"), cval.h, cval.m, cval.s);
	sprintf_P(lcd_buf_l2, PSTR("Time  %02u:%02u:%02u"), tval.h, tval.m, tval.s);
	lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
	
}
static inline void disp_temp(){
	
	int idx = 0;
	
	sprintf_P(lcd_buf_l1, PSTR("Temp t1, t2, t3"));
	
	idx += ds1820_print_temp(lcd_buf_l2 + idx, ds1820_get_cur(0));
	idx += sprintf_P(lcd_buf_l2 + idx, PSTR(" "));
	idx += ds1820_print_temp(lcd_buf_l2 + idx, ds1820_get_cur(1));
	idx += sprintf_P(lcd_buf_l2 + idx, PSTR(" "));
	idx += ds1820_print_temp(lcd_buf_l2 + idx, ds1820_get_cur(2));
	
	lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
}
void change_time(){
    
    char key = 0;
    
    sprintf_P(lcd_buf_l1, PSTR("Set time"));
    sprintf_P(lcd_buf_l2, PSTR("%02u:%02u:%02u"), _time_h, _time_m, _time_s);
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
    
    unsigned int idx = 0;
    do{
        key = keypad_get_input();   //Note that this is blockin function
        
        if((key >= '0') && (key <= '9')){
            
            lcd_buf_l2[idx++] = key;
            
            if(idx == 8){	//Stay on last character
                idx--;
            }
            
            if(idx == 2 || idx == 5){	//Jump over colons
                idx++;
            }
            
        }
        
        //Disp can be refreshed directly because keys are read with blocking function
        disp_refresh();
        
        //Cancel without changes
        if(key == 'C'){
            return;
        }
        
    }while(key != 'A');
    
    unsigned int h = 0, m = 0, s = 0;
    sscanf_P(lcd_buf_l2, PSTR("%u:%u:%u"), &h, &m, &s);	//Read user given data
    
    if((h < 24) && (m < 60) && (s < 60)){	//Check that input is valid
        _time_h = h;
        _time_m = m;
        _time_s = s;
    }
}
void ui_control_menu(){
	
	char key = 0;
	
	sprintf_P(lcd_buf_l1, PSTR("Control menu:"));
	sprintf_P(lcd_buf_l2, PSTR("1=Addr, 2=Clock, 0=Cancel"));
	lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
	
    key = keypad_get_input();
	
	if(key == '1'){
        //Support only IP changing for now
        change_addr_ip();
        //change_addr();
        return;
	}
    
    if(key == '2'){
        change_time();
        return;
    }
}
void change_addr_ip(){
    
    char key = 0;
    
    sprintf_P(lcd_buf_l1, PSTR("New IP"));
    sprintf_P(lcd_buf_l2, PSTR("%03d.%03d.%03d.%03d"), _network_ip_addr[0], _network_ip_addr[1], _network_ip_addr[2], _network_ip_addr[3]);
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
    
    unsigned int idx = 0;
    do{
        key = keypad_get_input();   //Note that this is blockin function
        
        if((key >= '0') && (key <= '9')){
            
            lcd_buf_l2[idx++] = key;
            
            if(idx == 15){	//Stay on last character
                idx--;
            }
            
            if(idx == 3 || idx == 7 || idx == 11){	//Jump over periods
                idx++;
            }
            
        }
        
        //Disp can be refreshed directly because keys are read with blocking function
        disp_refresh();
        
        //Cancel without changes
        if(key == 'C'){
            return;
        }
        
    }while(key != 'A');
    
    sscanf_P(lcd_buf_l2, PSTR("%u.%u.%u.%u"), _network_ip_addr, _network_ip_addr+1, _network_ip_addr+2, _network_ip_addr+3);	//Read user given data
    
}
static inline void disp_default(){
	sprintf_P(lcd_buf_l1, PSTR("NetController"));
	sprintf_P(lcd_buf_l2, PSTR(" "));
	lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
}
static inline void disp_refresh(){
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
}