void RTCC_isr(void) { //output_toggle(PIN_B6); switch(levelEnable){ case 0:output_a(level_0_Enable); output_c(cubeLevelC0); output_d(cubeLevelD0); break; case 1:output_a(level_1_Enable); output_c(cubeLevelC1); output_d(cubeLevelD1); break; case 2:output_a(level_2_Enable); output_c(cubeLevelC2); output_d(cubeLevelD2); break; case 3:output_a(level_3_Enable); output_c(cubeLevelC3); output_d(cubeLevelD3); break; } if (levelEnable == 3){ levelEnable = 0; }else{ levelEnable++; } output_toggle(PIN_B6); }
void LCD_Initialization() { output_low(LCD_CE); output_low(LCD_RS); output_low(LCD_RW); output_d(0); output_d(0x38); output_high(LCD_CE); Nop(); Nop(); output_low(LCD_CE); delay_ms(20); output_d(0x38); output_high(LCD_CE); Nop(); Nop(); output_low(LCD_CE); delay_ms(5); LCD_Cmd(DISPLAY_ON); // display on, curse off, blink off LCD_Cmd(0x01); // display on, curse off, blink off LCD_Cmd(0x06); // LCD clear, curse home LCD_Cmd(0x80); // initial DDRAM address LCD_Cmd(0x01); // LCD clear,curse home }
void main () { set_tris_a(0xff);//se pone el puerto RA analogo de entrada set_tris_d(0x00);//se pone el puerto RD en salida para prender los led setup_adc_ports(ALL_ANALOG);//configuracion de los puertos analogos setup_adc(ADC_CLOCK_DIV_32);//el osilador del ADC while (true) { set_adc_channel(0); delay_us(10); valor = read_adc(); if(valor){ output_d(0x01); }else{ output_d(0x00); } set_adc_channel(1); delay_us(10); valor = read_adc(); if{ output_d(0x02); }else{ output_d(0x00); } }
//Chuong trinh con stop-------------------------------------------------------// boolean program_Stop(void) { boolean value; int16 Stop_temp; if(Stop == 0){ //bit_set(denbao,2); denbao = 0x04; quangbao(); xoadong(1); lcd_putc("<- STOPED... ->"); xoadong(2); lcd_putc(" DUNG THAO TAC "); if(!Slide_Open_temp || !Slide_Close_temp){ output_d(0x10); xuat_E0(); value = 0; for (Stop_temp=1;Stop_temp<=1000;++Stop_temp){ delay_us(thoigianstop); if(!program_emergency()) break; } } output_d(0x00); xuat_E0(); } else { value = 1; } return value; }
void irq_rtcc_hi() { int8 val; if (nqueue(&txque0) > 0) { val=dequeue(&txque0); output_d(val); // output output_d(val&0x55); // mask step (force low) } }
void displayNumber(int n) { output_d(LED_MAP[n/10]); //printf("Count is %d", n/10); output_low(display1); delay_us(2000); output_high(display1); output_d(LED_MAP[n%10]); //printf("%d\r\n", n%10); output_low(display2); delay_us(2000); output_high(display2); }
void driverDisplay( timeDef *time ) { unsigned char Umin = 0; unsigned char Dmin = 0; unsigned char Uhora = 0; unsigned char Dhora = 0; unsigned char display = 0; unsigned char input = 0; //Carrego os valores de dezena e unidade dos minutos e horas Dmin = time->minuto/10; Umin = time->minuto - 10*Dmin; Dhora = time->hora/10; Uhora = time->hora - 10*Dhora; while( display < 4 ) { switch( display ) { case 0: //Carrego os dados da porta, para não mudar o estado do outro decoder( 2 ) input = portc&0xF0; //Carrego para os 4 bits menos significativos o estado atual do decoder 1 output_c( input |= bcdTable[ Umin ] ); break; case 1: //Carrego os dados da porta, para não mudar o estado do outro decoder input = portc&0x0F; //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 2 output_c( input | ( bcdTable[ Dmin ]<<4 ) ); break; case 2: //Carrego os dados da porta, para não mudar o estado do outro decoder( 3 ) input = portd&0xF0; //Carrego para os 4 bits menos significativos o estado atual do decoder 4 output_d( input |= bcdTable[ Uhora ] ); break; case 3: //Carrego os dados da porta, para não mudar o estado do outro decoder input = portd&0x0F; //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 4 output_d( input | ( bcdTable[ Dhora ]<<4 ) ); break; } display++; } }
void LCD_AddrSet(int addr) { Busy(); output_d(addr+DDRAM); output_high(LCD_CE); output_low(LCD_CE); }
//============================================================================= void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0xFF);//7F set_tris_b(0xFF); //FF set_tris_c(0x94);//94 set_tris_d(0xFF); //02 set_tris_e(0xF0); //f0 set_tris_f(0xFF);//ff set_tris_g(0xFC); //04 output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); }
// ** Grundinitialisierung ** void coldstart () { setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_VDD); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); setup_oscillator(OSC_8MHZ|OSC_INTRC); setup_comparator(NC_NC_NC_NC); output_a (0b00001000); output_b (0); output_c (0); output_d (0); output_e (0); set_tris_a (TRISA_INIT); // Datenrichtung Port A set_tris_b (TRISB_INIT); // Datenrichtung Port B set_tris_c (TRISC_INIT); set_tris_d (TRISD_INIT); set_tris_e (TRISE_INIT); port_b_pullups(TRUE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_BIT); // Timer0 intern, Takt 20.00/4/64 = 78.125 KHz // Interrupt alle 256/15.625 = 3.2768 ms (305Hz) // Korrekturwert für 10 ms: 156 Timerclicks // -> Timer wird auf 256-156=100 vorgestellt set_timer0 (Timerstartwert_K); // Timerwert auf Startwert setzen enable_interrupts(INT_TIMER0); setup_timer_1(T1_DISABLED); // Nur Timer0 Interrupt delay_ms (200); }
//PROGRAMA PRINCIPAL void main () { int8 DisNumbs[10] = { //Este arreglo guarda los códigos para la representación de los números en el display. 0b00111111, //0 0b00000110, //1 0b01011011, //2 0b01001111, //3 0b01100110, //4 0b01101101, //5 0b01111101, //6 0b00000111, //7 0b01111111, //8 0b01101111 //9 }; //Parámetros de Timer0. setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); //Habilitación de interrupciones. enable_interrupts(INT_RTCC); enable_interrupts(GLOBAL); //Parámetros del ADC. setup_adc_ports(RA0_ANALOG); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); delay_us(10); //Se requiere un pequeño delay para estabilizar la señal al cambiar de canal. //Puertos usados para displays en salida. set_tris_b(0x00); set_tris_c(0x00); set_tris_d(0x00); output_b(0x00); output_c(0x00); output_d(0x00); while (true) { //Se le da salida a los números calculados de acuerdo al display al que están conectados. if (readSens){ readSens=false; ValAnalog = read_adc(); //Se lee y convierte el valor analógico a digital. Temperatura = (float)ValAnalog * (0.48875); //Se convierte el valor digital a ºC Calcs(); } output_b(DisNumbs[Decena]); output_c(DisNumbs[Unidad]); output_d(DisNumbs[Decimal]); } }
void LCD_Cmd(int cmd) { output_d(cmd); output_low(LCD_RS); output_low(LCD_RW); output_high(LCD_CE); delay_ms(2); output_low(LCD_CE); delay_ms(2); output_high(LCD_CE); }
void driverDisplay( unsigned long int temp ) { unsigned char Ucount = 0; unsigned char Dcount = 0; unsigned char Ccount = 0; unsigned char display = 0; unsigned char input = 0; //Carrego os valores de dezena e unidade dos minutos e horas Ccount = temp/100; Dcount = ( temp - Ccount*100 ); Dcount = Dcount/10; Ucount = ( temp - Ccount*100 ) - 10*Dcount; while( display < 3 ) { switch( display ) { case 0: //Carrego os dados da porta, para não mudar o estado do outro decoder( 2 ) input = portc&0xF0; //Carrego para os 4 bits menos significativos o estado atual do decoder 1 output_c( input |= bcdTable[ Ucount ] ); break; case 1: //Carrego os dados da porta, para não mudar o estado do outro decoder input = portc&0x0F; //Faço um deslocamento de 4 bits para poder carregar o valor correto para o decoder 2 output_c( input | ( bcdTable[ Dcount ]<<4 ) ); break; case 2: //Carrego os dados da porta, para não mudar o estado do outro decoder( 3 ) input = portd&0xF0; //Carrego para os 4 bits menos significativos o estado atual do decoder 4 output_d( input |= bcdTable[ Ccount ] ); break; break; } display++; } }
void blinkLeds() { if (alarmActived) { output_high(PIN_B1); } else { output_low(PIN_B1); } if (state == Normal) { output_low(PIN_B2); output_low(PIN_B3); } else if (state == ModeAlarmMin || state == ModeAlarmHour) { output_high(PIN_B3); output_low(PIN_B2); } else { output_high(PIN_B2); output_low(PIN_B3); } if (state != ModeAlarmMin && state != ModeAlarmHour) { output_c(getClockHour()); output_d(getClockMin()); } else { output_c(getAlarmHour()); output_d(getAlarmMin()); } }
void glcd_writeByte(char chip, BYTE data) { if(chip == GLCD_CS1) // Choose which chip to write to output_high(GLCD_CS1); else output_high(GLCD_CS2); output_low(GLCD_RW); // Set for writing output_d(data); // Put the data on the port output_high(GLCD_E); // Pulse the enable pin delay_us(2); output_low(GLCD_E); output_low(GLCD_CS1); // Reset the chip select lines output_low(GLCD_CS2); }
void sendLCD(int address, int n) { output_low (LCD_E); delay_us (60); /*Might be a little long?*/ if(address) output_high (LCD_RS); else output_low (LCD_RS); delay_cycles(1); output_d (n); output_high (LCD_E); delay_ms (1); output_low (LCD_E); delay_ms(5); }
void sendLCD(int address, int n) { output_low (LCD_E); delay_us (60); if(address) output_high (LCD_RS); else output_low (LCD_RS); delay_cycles(1); output_d (n); output_high (LCD_E); delay_ms (1); output_low (LCD_E); delay_ms(5); }
void setupLCD(void) { int i; output_low(LCD_E); delay_ms(15); for(i=0 ; i < 3; i++) { output_d (0x30); delay_ms(5); } for(i=0; i < sizeof(LCD_INIT_STRING); i++) { sendLCD(0, LCD_INIT_STRING[i]); } }
/** * Exibe tempo nos displays **/ void exibe_relogio(int horas, int minutos) { int hora_dezena_byte = 0; int hora_unidade_byte = 0; int minuto_dezena_byte = 0; int minuto_unidade_byte = 0; // mapear horas no array de bytes hora_dezena_byte = horas / 10; // ex.: 16 => (int)16/10 == 1 e 16%10 == 6 hora_unidade_byte = horas % 10; output_c(dezena[hora_dezena_byte]|unidade[hora_unidade_byte]); // mapear minutos no array de bytes minuto_dezena_byte = minutos / 10; minuto_unidade_byte = minutos % 10; output_d(dezena[minuto_dezena_byte]|unidade[minuto_unidade_byte]); }
void Busy() { int LCD_Busy; delay_us(10); // debug do { output_d(0); output_high(LCD_RW); output_high(LCD_CE); LCD_Busy = (input_d()) & 0x80; // busy flag mask : bit7 output_low(LCD_CE); } while (LCD_Busy); delay_ms(2); // debug output_low(LCD_CE); output_low(LCD_RS); output_low(LCD_RW); }
//Chuong trinh con Emergency--------------------------------------------------// boolean program_emergency() { boolean value; if(SW_Emergency == 0) { denbao = 0x40; quangbao(); output_d(0x00); xuat_E0(); xoadong(1); lcd_putc("<- EMERGENCY... ->"); xoadong(2); lcd_putc(" DUNG MOI THAO TAC "); value = 0; } else { value = 1; } return value; }
void Portout (int Li_B,int Re_B) { int Out_B = 0, I_B; for(I_B=0;I_B <=3;++I_B) Out_B |= bit_test (Li_B,(3-I_B)) << I_B; // Bit0-3 auf 7-4 swap (Out_B); swap (Re_B); for(I_B=0;I_B <=3;++I_B) Out_B |= bit_test (Re_B,(I_B)) << I_B; Out_B ^= 255; output_d (Out_B); Out_B = 0; swap (Li_B); for(I_B=0;I_B <=3;++I_B) Out_B |= bit_test (Li_B,(3-I_B)) << I_B; swap (Out_B); swap (Re_B); for(I_B=0;I_B <=3;++I_B) Out_B |= bit_test (Re_B,(I_B)) << I_B; Out_B ^= 255; output_c (Out_B); }
void DisplayChar(int row,int offset,char data) { int ROW_Addr; switch (row) { case 0 : ROW_Addr=ROW1; break; case 1 : ROW_Addr=ROW2; break; case 2 : ROW_Addr=ROW3; break; case 3 : ROW_Addr=ROW4; break; } output_low(LCD_CE); output_low(LCD_RS); output_low(LCD_RW); LCD_AddrSet(ROW_Addr+offset); Busy(); output_d(data); output_high(LCD_RS); output_high(LCD_CE); output_low(LCD_CE); output_low(LCD_RS); }
//------------------------------------------------------------------------------ void init_prog(void) { setup_wdt(WDT_OFF); setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0 setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(OSC_32MHZ); set_tris_a(0x00); set_tris_b(0x24); set_tris_c(0x80); set_tris_d(0x00); set_tris_e(0x15); set_tris_f(0x58); set_tris_g(0x10); output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00); output_e(0x00); output_f(0x00); output_g(0x00); // RF Modul and PA/LNA activation IOpin.modulepower=0; IOpin.moduleCTX=1; IOpin.moduleCPS=0; IOpin.modulePWRUP=1; }
void pet_userport_joystick_adapter_device::update_port1() { //printf( "update port1\n" ); output_c(m_up1 && m_fire1); output_d(m_down1 && m_fire1); }
void main() { set_timer0(0); setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); enable_interrupts(INT_RTCC); enable_interrupts(GLOBAL); //ext_int_edge(H_TO_L); //enable_interrupts(INT_EXT); //enable_interrupts(GLOBAL); //Cai dat vao ra trisa = 0xff; trisb = 0x00; trisc = 0xff; trisd = 0xff; trisd = 0x00; trise= 0x00; output_d(0x00); // TODO: USER CODE!! lcd_init(); welcome(); denbao = 0x00; Open_temp = false; //Bien trung gian bao dang thuc hien mo cua Close_temp = false; //Bien trung gian bao dang thuc hien dong cua Slide_Open_temp = false; Slide_Close_temp = false; error_open_slide = false;//Kiem tra loi khi dong cua. error_close_slide = false; temp_quetlcd = 7; //Cai dat ban dau se kiem tra vi tri cua. keyCode = 0; /* xoadong(1); lcd_putc(thongbao[0]); delay_ms(3000); xoadong(1); lcd_putc(thongbao[1]); delay_ms(3000); lcd_putc(thongbao[2]); delay_ms(3000);*/ while(1) { if(SW_Emergency != 0){ kiemtra_vitri(); if(Open == 0) { program_Open(); }else if(Close == 0){ program_Close(); }else if(Semi_Open == 0){ program_Open_Semi(); }else if(Open_Slide == 0){ program_Open_Slide(); }else if(Close_Slide == 0){ program_Close_Slide(); } else if(Stop == 0) { bit_clear(denbao,7); quangbao(); D7 = 0; xuat_E0(); temp_quetlcd = 7; //Cai dat ban dau se kiem tra vi tri cua. } switch(keyCode) { case 1: program_Close_Slide();Break; case 2: program_Open_Slide();Break; case 3: program_Close();Break; case 4: program_Open();Break; } bit_clear(denbao,6); quangbao(); } else { lcd_gotoxy(1,1); lcd_putc("<- EMERGENCY... ->"); lcd_gotoxy(1,2); lcd_putc(" DUNG MOI THAO TAC "); denbao = 0x40; quangbao(); temp_quetlcd = 7; //Cai dat ban dau se kiem tra vi tri cua. } //printf(lcd_putc," keyCode = %u",debug); } }
/** * Reseta display **/ void clean_displays() { output_c(dezena[0]|unidade[0]); output_d(dezena[0]|unidade[0]); }