void LCD_Init(void){ // LCD instellingen OpenXLCD(DON); OpenXLCD(FOUR_BIT&LINES_5X7); // 8 bits datalijn, meerdere regels while (BusyXLCD()); WriteCmdXLCD(SHIFT_DISP_LEFT); // cursor instelling while (BusyXLCD()); WriteCmdXLCD(CURSOR_ON&BLINK_OFF); //cursor uit, knipperen uit }
void initLCD(void) { OpenXLCD(FOUR_BIT & LINES_5X7); SetDDRamAddr(0x00); WriteDataXLCD('1'); WriteCmdXLCD(DON&CURSOR_OFF&BLINK_OFF); }
/**************Initialise LCD****************/ void mInitLCD(void) { // Initialise LCD for 4 bit operation and multiple line operation OpenXLCD( FOUR_BIT & LINES_5X7 ); // configure external LCD // Initialise display so that neither cursor nor blink is ON while(BusyXLCD()); WriteCmdXLCD(0b00000001); // Reset Display // Initialise display so that neither cursor nor blink is ON while(BusyXLCD()); WriteCmdXLCD(0b00001100); // Last three digits are display ON, Cursor OFF, Blink OFF // Initialise display as what to show: // Money:XXXXXXXp // Energy:XXXXXWh while(BusyXLCD()); SetDDRamAddr( 0x00 ); // Put the cursor in the correct position //Blank the bottom line, just in case while(BusyXLCD()); putrsXLCD(dataArrayInit); while(BusyXLCD()); SetDDRamAddr( 0x40 ); // Put the cursor in the correct position //Blank the bottom line, just in case while(BusyXLCD()); putrsXLCD(dataArrayInit); }//end Initialise LCD routine
void initLCD(void) { OpenXLCD(FOUR_BIT & LINES_5X7); SetDDRamAddr(0x00); WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON); // utilizei um display padrao 16x2 caracteres // I used a common LCD of 16x2 characters }
void main(void) { ADCON1 = 0b11111111; // Configure all pins digital // For me it not want work without it //******** Configure LCD for four line communication and 5X7 line display ********************************* OpenXLCD(FOUR_BIT & LINES_5X7); while( BusyXLCD() ); //wait untill LCD controller is busy WriteCmdXLCD(CURSOR_OFF); while( BusyXLCD() ); WriteCmdXLCD(BLINK_OFF); while( BusyXLCD() ); //************************************************************************************************************* while(1){ //*********** Set the starting address in the LCD RAM for display. This determines the location of display ******** SetDDRamAddr(0x80); while( BusyXLCD() ); //wait untill LCD controller is busy putsXLCD(LCD_text1); //Display string of text while( BusyXLCD() ); //wait untill LCD controller is busy //********** Set the address in second line for display **************************************************** SetDDRamAddr(0xC0); while( BusyXLCD() ); //wait untill LCD controller is busy putsXLCD(LCD_text2); //Display string of text while( BusyXLCD() ); //wait untill LCD controller is busy WriteCmdXLCD(SHIFT_DISP_LEFT); while( BusyXLCD() ); } }
void initLCD(void) { OpenXLCD(FOUR_BIT & LINES_5X7); WriteCmdXLCD(DON & CURSOR_OFF & BLINK_OFF); }
/****************************************************************************************************** * Funcao: void main(void) * * Entrada: Nenhuma * * Saída: Nenhuma * * Descrição: Função principal do programa. * ******************************************************************************************************/ void main(void) { unsigned char pass_flag = 0; ConfiguraSistema(); ConfiguraUSART(); OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD(" Welcome "); while(1) { OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD("Send or receive? "); // display " Send or Receive ? " if(send == 1) // if sending switch is pressed { OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD(" Sending .. "); // display "sending.." pass_flag = 0; while (!pass_flag) { for(j = 89; j > 0; j--){ data[j] = ' '; } Transmitir(sms_format, sizeof(sms_format)); // send to GSM ( set Text mode) Delay10KTCYx(250); //Tempo determinado pelo datasheet SIM300 pg 24 Delay10KTCYx(250); if(data[0] == ~'O' && data[1] == ~'K'){ pass_flag = 1; } } pass_flag = 0; while (!pass_flag) { for(j = 89; j > 0; j--) data[j] = ' '; Transmitir(character_set, sizeof(character_set)); // send to GSM Delay10KTCYx(250); Delay10KTCYx(250); if(data[0] == ~'O' && data[1] == ~'K'){ pass_flag = 1; } } Transmitir(sms_write, sizeof(sms_write)); // send to GSM ( to write phone number) Delay10KTCYx( 250); Delay10KTCYx( 250); Delay10KTCYx( 250); Delay10KTCYx( 250); Delay10KTCYx( 250); Transmitir(sms, sizeof(sms)); // send to GSM ( to write the sms) Delay10KTCYx(250); Delay10KTCYx(250); Tx_Mensagem(sms_terminate); // ctrl+z Delay10KTCYx(250); Delay10KTCYx(250); Tx_Mensagem(enter); // enter Key Delay10KTCYx(250); OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD("SMS Sent..."); // display "SMS Sent .." } if(rec == 1) //if Receiving switch is pressed { OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD(" Waiting for SMS"); // display " waiting for sms" Transmitir(sms_format, sizeof(sms_format)); // to set the mode Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); Transmitir(sms_indication, sizeof(sms_indication)); // to choose how sms arrive Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); Rx_Mensagem(); for(k = 0; k < 46; k++) { stringArray[k] = ch; } // --- By this point the SMS is Received and stored in Array -- OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD(" SMS Received "); // display ( sms received ) Transmitir(stringArray, sizeof(stringArray)); // to set the mode Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); /*--- display SMS on LCD ---*/ OpenXLCD(); SetDDRamAddr(0x00); putrsXLCD(stringArray); // display the text that received } } }//fim main
void main(void) { //IRCF0_bit=0b0; //IRCF1_bit=0b0; //IRCF2_bit=0b1; //OSCCON=0b100; // 1mhz //OSCCON=0b001; // 125 khz //OSCCONbits.SCS1=1; // internal oscillator block OSCCONbits.IRCF0 = 0b1; OSCCONbits.IRCF1 = 0b1; OSCCONbits.IRCF2 = 0b1; //para 100 (osconbits 210), osciloscopio acusou 250 khz short int cont; TRISB = 0; TRISC = 0; /* TRISCbits.RC3=0; TRISCbits.RC2=0; TRISCbits.RC1=0; */ PORTC = 0x00; for (cont=0; cont<2; cont++) { //LATC3=1; //LATC2=1; //LATC1=1; PORTC=0b1111; Delay10KTCYx(1000); //LATC3=0; //LATC2=0; //LATC1=0; PORTC=0b0000; Delay10KTCYx(1000); } OSCCONbits.IRCF0 = 0b0; OSCCONbits.IRCF1 = 0b1; OSCCONbits.IRCF2 = 0b1; // 4mhz LATC3=0; LATC2=0; LATC1=0; Delay10KTCYx(2000); OpenXLCD(FOUR_BIT & LINES_5X7); WriteDataXLCD('H'); WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON); char data[]="Finalmente Rodou"; while (1) { PORTC=0; for (cont= 0b0001 ; cont <= 0b1111 ; cont=cont*2) { PORTC = cont; Delay10KTCYx(10); } PORTC=0; OSCCONbits.IRCF0 = 0b1; OSCCONbits.IRCF1 = 0b1; OSCCONbits.IRCF2 = 0b0; // 500 khz while(BusyXLCD()); WriteCmdXLCD(0x01); Delay10KTCYx(250); OSCCONbits.IRCF0 = 0b0; OSCCONbits.IRCF1 = 0b0; OSCCONbits.IRCF2 = 0b0; // 31 khz while(BusyXLCD()); putrsXLCD("Lcd Testando.."); Delay10KTCYx(2); /* Set DDRam address to 0x40 to display data in the second line */ SetDDRamAddr(0x40); putrsXLCD(data); Delay10KTCYx(2); OSCCONbits.IRCF0 = 0b0; OSCCONbits.IRCF1 = 0b0; OSCCONbits.IRCF2 = 0b1; // 1 mhz Delay10KTCYx(1000); } }
void main (void) { /* TIMER 1*/ OpenTimer1( TIMER_INT_ON & T1_16BIT_RW & T1_SOURCE_EXT & T1_PS_1_1 & T1_OSC1EN_ON & T1_SYNC_EXT_OFF );// tem que estar off para correr na placa, mas on para correr no proteus ADCON1 = 0x0E; // Port A: A0 - analog; A1-A7 - digital OpenADC (ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_1ANA_0REF, ADC_CH0 & ADC_INT_OFF); /* BUTTON S3 */ OpenRB0INT ( PORTB_CHANGE_INT_ON & /* enable the RB0/INT0 interrupt */ PORTB_PULLUPS_ON & /* configure the RB0 pin for input */ FALLING_EDGE_INT); /* trigger interrupt upon S3 button depression */ OpenXLCD( FOUR_BIT & LINES_5X7 ); // 4-bit data interface; 2 x 16 characters OpenI2C(MASTER, SLEW_ON);// Initialize I2C module SSPADD = 9; //400kHz Baud clock(9) @16MHz //100kHz Baud clock(39) @16MHz InitializeBuzzer(); init_LVD(); EnableHighInterrupts(); alarmes[0] = 'a'; alarmes[1] = 0; alarmes_prev[0] = 'a'; alarmes_prev[1] = 0; checksumIsRight = verificar_checksum(); if(checksumIsRight == 1){ ler_EEPROM_interna_parametros(); ler_EEPROM_interna_relogio(); ler_EEPROM_interna_relogio_alarme(); // carregar da EEPROM interna o valor do alarme do relogio ler_EEPROM_interna_temp_alarme(); // carregar da EEPROM interna o valor do alarme da temperatura ler_EEPROM_interna_lum_alarme(); // carregar da EEPROM interna o valor do alarme da luminosidade } ler_EEPROM_interna_relogio_seconds(); update_EEPROM_interna_parametros(); update_EEPROM_interna_relogio_alarme(); update_EEPROM_interna_temp_alarme(); update_EEPROM_interna_lum_alarme(); update_EEPROM_interna_relogio_hours(); update_EEPROM_interna_relogio_minutes(); init_EEPROM_externa(); WriteTimer1( 0x8000 ); // load timer: 1 second /////////////////////////////////////////////////////////////////////////////// //*************************** Ciclo Principal *******************************// /////////////////////////////////////////////////////////////////////////////// while (1){ if(modo_sleep == 1 && cursor_pos == 8){ WriteCmdXLCD( DOFF ); // Turn display off } else{ while( BusyXLCD() ); WriteCmdXLCD( DOFF ); // Turn display off while( BusyXLCD() ); WriteCmdXLCD( CURSOR_OFF );// Enable display with no cursor while( BusyXLCD() ); } sd = seconds/10; su = seconds%10; md = minutes/10; mu = minutes%10; hd = hours/10; hu = hours%10; SetDDRamAddr(0x0D); putsXLCD(alarmes); rotina_verificacao_alarmes(); rotina_modo_modificacao(); rotina_sai_modificacao(); avisa_alarmes(); rotina_sensores_PMON(); if(CCP1CON == 0x00 && modo_modificacao == 0){ modo_sleep = 1; Sleep(); } } }
//============================================================================= // Main Program //============================================================================= void main (void) { // Set I/O input output TRISA = 0b11111111; TRISB = 0b00000011; TRISC = 0b11111101; TRISD = 0b00000000; // Configure PORTD I/O direction ANSEL0 = 0b11100111; // RA3 and RA4 set as digital input PORTB = 0; // Clear Port B PORTD = 0; // Clear Port D // Configure for Quadrature Encoder Interface QEICON = 0b00011000; // QEI enabled in 4x update mode POSCNTH=0; // Clear position count register (high byte) POSCNTL=0; // Clear position count register (low byte) // Configuration for PWM output (controlling motor speed) T2CON = 0b00000101; // Timer 2 on CCP2CON = 0b00001100; // PWM mode PR2 = 0b11111111; // PR2 set to 255 // Configuration for timer interrupt (100Hz, PID control update use) T1CON = 0b00000001; RCONbits.IPEN = 1; INTCONbits.GIE = 1; INTCONbits.PEIE = 1; PIE1bits.TMR1IE = 1; IPR1bits.TMR1IP = 1; PIR1bits.TMR1IF = 0; Delay_1msX(1); // Delay for 1ms // Configuration for external LCD OpenXLCD( EIGHT_BIT & LINES_5X7 ); ClearXLCD(); // Clear display // Program start here putrsXLCD("SPG-30E Quad Enc"); // Send string to LCD SetCurXLCD(20); // Cursor go to lower line (refer xlcd.c for detail) putrsXLCD("Position:"); // Send string to LCD brake; // Motor brake while(1) { if(!sw1) // Test for SW1 pressing { PIDEnable = 1; // Enable interrupt for PID control while(1) // Motor running for mode 1 { DesirePosition=120; DelayAndPositionDisplay(70); DesirePosition=210; DelayAndPositionDisplay(70); DesirePosition=300; DelayAndPositionDisplay(70); DesirePosition=390; DelayAndPositionDisplay(70); DesirePosition=480; DelayAndPositionDisplay(70); DesirePosition=390; DelayAndPositionDisplay(70); DesirePosition=300; DelayAndPositionDisplay(70); DesirePosition=210; DelayAndPositionDisplay(70); } } else if(!sw2) // Test for SW2 pressing { PIDEnable = 1; // Enable interrupt for PID control while(1) // Motor running for mode 2 { DesirePosition=120; DelayAndPositionDisplay(250); DesirePosition=1200; DelayAndPositionDisplay(250); } } DelayAndPositionDisplay(1); } }//End of main
void setupLCD(void) { TRISDbits.RD7 = 0; OpenXLCD(FOUR_BIT & LINES_5X7); WriteCmdXLCD(SHIFT_DISP_LEFT); clearLCD(); }
int main( void ) { int adcvalue; char buf[20]; Setup(); //LCD display OpenXLCD(FOUR_BIT&LINES_5X7); Delay(50000); while(BusyXLCD()); SetDDRamAddr(0); putsXLCD("EE4207 Lab"); while(BusyXLCD()); SetDDRamAddr(0x40); putsXLCD("Demo 1"); while(1) { adcvalue = ReadADC(7); if (adcvalue <200 && adcvalue >=0) { LED1 = 0; LED2 = 0; LED3 = 0; LED4 = 0; } if (adcvalue <400 && adcvalue >=200) { LED1 = 1; LED2 = 0; LED3 = 0; LED4 = 0; } if (adcvalue <600 && adcvalue >=400) { LED1 = 1; LED2 = 1; LED3 = 0; LED4 = 0; } if (adcvalue <800 && adcvalue >=600) { LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 0; } if (adcvalue >800) { LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 1; } sprintf(buf, "%d ", adcvalue); SetDDRamAddr(0x47); putsXLCD("ADC="); SetDDRamAddr(0x4B); putsXLCD(buf); } // end while(1) } // end main