void main() { Initial(); //Initialize all settings required for general QwikFlash and LCD operation DisplayC(Clear1); //Clear the LCD one time at the beginning of your program DisplayC(Clear2); long retTen; // initialize variable for 10K ohm potentiometer long retPot; // initialize variable for Potentiometer 1 on circuit board SSPSTAT = 0b11000000; // SMP and CKE SSPCON1 = 0b00100000; // Enable SPI serial port //Your personal PORT/TRIS/ADCON/etc settings or configurations can go here //Or make your own function and call it while(1) { Delay10KTCYx(25); retTen = tenK(); // Store value from 10K ohm potentiometer Delay10KTCYx(25); retPot = pot1(); // Store value from Potentiometer 1 on circuit board displayAnalog(retTen, retPot); } }
void interruptions_left(void) //for interruptions appearing on the left to the track { straight_fwd(); // Go forward Delay10KTCYx(130); check_sensors(); if (SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //10100 { while(SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000 sees nothing { //spin right spin_right(); check_sensors(); } } else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&SeeLine.b.Right) //00101 { straight_fwd(); // Go forward Delay10KTCYx(130); check_sensors(); if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000 { while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000 { spin_right(); check_sensors(); } } } * }
// LED indication for PIR true void pirIndicate(void) { LED = 1; Delay10KTCYx(20); LED = 0; Delay10KTCYx(20); }
void initialize() ///Works with current delays { int result; result = enterCommandMode(); sendString(GET_WLAN_STRING, 6); Delay10KTCYx(0); sendString(SET_SSID, 18); Delay10KTCYx(0); sendString(SET_PASSPHRASE, 29); Delay10KTCYx(0); sendString(SET_CHANNEL, 10); Delay10KTCYx(0); sendString(SET_AUTH, 10); Delay10KTCYx(0); sendString(SET_JOIN, 10); Delay10KTCYx(0); sendString(SET_DHCP, 10); Delay10KTCYx(0); sendString(SET_COMM_OPEN, 10); Delay10KTCYx(0); sendString(SET_COMM_REMOTE, 10); Delay10KTCYx(0); autoConnect(); sendString(SAVE, 5); Delay10KTCYx(0); result = rebootModule(); longDelay(); }
int botao() { if (botao1==0) { Delay10KTCYx(10); if (botao1==0) return 1; } else if (botao2==0) { Delay10KTCYx(10); if (botao2==0) return 2; } else if (botao3==0) { Delay10KTCYx(10); if (botao1==0) return 3; } else if (botao4==0) { Delay10KTCYx(10); if (botao4==0) return 4; } else return 0; }
// Configure and start temperature sensor void configStartTempSensor(void) { // Set configuration register StartI2C(); WriteI2C(0x9E); // slave address + W IdleI2C(); WriteI2C(0xAC); // access configuration IdleI2C(); WriteI2C(0x00); // set config IdleI2C(); StopI2C(); // Need at least a 10msec delay (from data sheet) Delay10KTCYx(40); // Start temperature conversion StartI2C(); WriteI2C(0x9E); // slave address + W IdleI2C(); WriteI2C(0xEE); // start conversion IdleI2C(); StopI2C(); // Another delay Delay10KTCYx(40); }
void main(void) { ConfigureOscillator(); TRISB0 = 0; TRISB1 = 0; TRISB4 = 1; TRISA1 = 1; //unsigned char channel = 0x00, config1 = 0x00, config2 = 0x00, config3 = 0x00, portconfig = 0x00, i = 0; //CloseADC(); //config1 = ADC_FOSC_2 | ADC_RIGHT_JUST | ADC_2_TAD; //config2 = ADC_CH0 | ADC_INT_OFF | ADC_REF_VDD_VSS; //portconfig = ADC_4ANA; //OpenADC(config1, config2, portconfig); /* ADCON0bits.ADON = 0b1; ADCON0bits.CHS = 0b00; ADCON1bits.VCFG0 = 0b0; ADCON1bits.PCFG0 = 0b1; ADCON2bits.ADFM = 0b1; ADCON2bits.ADCS = 0b000; */ //ADC_INT_ENABLE(); while(1){ //ConvertADC(); //while (BusyADC()); //ADCResult = PORTAbits.RA1;//(unsigned int) ReadADC(); // if(ADCResult==1){ LATB0 = 1; // RB-0 to High LATB1 = 1; // RB-1 to High Delay10KTCYx(30); // }else{ LATB0 = 0; // RB-0 to High LATB1 = 0; // RB-1 to High //} Delay10KTCYx(30); } /* while (1) { //PORTBbits.RB1=0b1 //if(PORTBbits.RB4==0){ LATBbits.LATB0 = 1; // RB-0 to High LATBbits.LATB1 = 0; // RB-1 to High //delays(1); Delay10KTCYx(30); // } // if(PORTBbits.RB4==1){ LATBbits.LATB0 = 0; // RB-0 to LOW LATBbits.LATB1 = 1; // RB-1 to LOW //delays(1); Delay10KTCYx(30); // } }*/ }
void delay_1Sx(int n){ for(int i =0; i<n; i++){ Delay10KTCYx(250); // Delay 2,500,000 Cycles = 0.25 seconds Delay10KTCYx(250); // Delay 2,500,000 Cycles = 0.25 seconds Delay10KTCYx(250); // Delay 2,500,000 Cycles = 0.25 seconds Delay10KTCYx(250); // Delay 2,500,000 Cycles = 0.25 seconds } }
void main(void) { unsigned char slave7bitAddr = 0x2A; //7-bit address of Slave. MSB=Don't care. unsigned char slaveAddrWrite = (slave7bitAddr << 1); //LSB=0, Master Write request. signed char writeStat; unsigned char message[11] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'}; OSCCONbits.IRCF = 0b111; //Set internal oscillator to 16mHz //Must set SCL(pin RC3)and SDA(pin RC4) as inputs and enable digital buffers. TRISCbits.TRISC3 = 1; //set input TRISCbits.TRISC4 = 1; ANSELCbits.ANSC3 = 0; //enable digital buffer ANSELCbits.ANSC4 = 0; OpenI2C1(MASTER, SLEW_OFF); //If you switch to 400kHz (see below) set SLEW_ON /* You can ignore all I2C "unable to resolve identifier" errors assuming you didn't make any typos. Don't forget the "1"'s. */ /* Now set the I2C clock speed. I2C Master always controls clock. For 400kHz use 1k pullup resistors and for 100kHz use 2.2k ohms */ SSP1ADD = 0x27; //100Khz = FOSC/(4 * (SSPADD + 1)) = 16E6/((39 + 1) * 4)note:39=0x27 //SSP1ADD = 0x09; //400Khz = FOSC/(4 * (SSPADD + 1)) = 16E6/((9 + 1) * 4) while (1) { IdleI2C1(); //Wait for bus to become idle. StartI2C1(); //Begin I2C communication IdleI2C1(); //send slave address (w/write request bit) and wait for slave to reply. do { writeStat = WriteI2C1(slaveAddrWrite); //Send address with LSB=Write if (writeStat == -1) { //Detected bus collision - More than one master? unsigned char data = SSP1BUF; //clear the buffer by reading it. SSPCON1bits.WCOL = 0; //clear the bus collision status bit } else if (writeStat == -2) { //NACK (no acknowledge rx'd) //Is the slave on and ready? Did we send the correct address? } } while (writeStat != 0); //Keep repeating until slave acknowledges. //Slave has Ack'd so we can send our Hello World message now. for (int x = 0; x <= 10; x++) { do { writeStat = (WriteI2C1(message[x])); if (writeStat == -2) { //NACK (no acknowledge rx'd) //Is the slave on and ready? Using the correct pullups? } } while (writeStat != 0); //Keep repeating until slave acknowledges. } IdleI2C1(); StopI2C1(); //Delay about 1 sec and then repeat. 1sec = ((10K*200*2)/(16E6/4) Delay10KTCYx(200); Delay10KTCYx(200); } }
/* * MAIN */ int main(int argc, char** argv) { // RA1 as DO LATA = 0; ADCON1 = 0x06; TRISA1 = 0; LATA1 = 1; // I2C configuration i2c_setup(); unsigned char w; for(w=0;w<20;w++) I2C_Recv[w]=0; unsigned int temps = 25; unsigned char temp, length=0; while(1){ LATA1 = ~LATA1; Delay10KTCYx(temps); check_interruptions(); if (DataRdyI2C()==1) { temps += 25; temp = ReadI2C(); //********************* Data reception from master by slave ********************* do { while(DataRdyI2C()==0); // WAIT UNTILL THE DATA IS TRANSMITTED FROM master I2C_Recv[length++]=getcI2C(); // save byte received } while(length!=20); } } //******************** write sequence from slave ******************************* while(SSPSTATbits.S!=1); //wait untill STOP CONDITION //********************* Read the address sent by master from buffer ************** while(DataRdyI2C()==0); //WAIT UNTILL THE DATA IS TRANSMITTED FROM master temp = ReadI2C(); //********************* Slave transmission ************************************ if(SSPSTAT & 0x04) //check if master is ready for reception while(putsI2C(I2C_Send)); // send the data to master //-------------TERMINATE COMMUNICATION FROM MASTER SIDE--------------- CloseI2C(); //close I2C module while(1) { LATA1 = ~LATA1; Delay10KTCYx(100); }; //End of program return (EXIT_SUCCESS); }
void msg_inicial() { printf("Kit de Desenvolvimento ACEPIC 28\r\n"); Delay10KTCYx(1); //Gera um delay de 5ms printf("Microcontrolador: PIC 18F2550\r\n"); Delay10KTCYx(1); //Gera um delay de 5ms printf("\r\n-Envie AD0 para retornar Conversao A/D do Canal 0.\r\n"); Delay10KTCYx(1); //Gera um delay de 5ms printf("-Envie TMP para retornar Conversao A/D do Canal 3. (Temperatura)\r\n\r\n"); }
// LED indicator void eventL(void) { LED = 1; Delay10KTCYx(10); LED = 0; Delay10KTCYx(10); LED = 1; Delay10KTCYx(10); LED = 0; Delay10KTCYx(10); }
void DelayS(unsigned long seconds) { unsigned long count; for(count = 0; count < seconds; count++) { Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); } }
void main(void) { int count = 0; char buffer[20]; OSCCON = OSCCON_VALUE; // Sets 16MHz modemSetup(); aprsMakeCallsignPgm(&(s_packet.to), APRS_ADDRESS_TEST, APRS_DESTINATION_SSID_NONE); aprsMakeCallsignPgm(&(s_packet.from), "M0RJC", 9); aprsSetLastAddress(&(s_packet.from)); while(1) { modemTxMode(); modemStartTone(0); Delay10KTCYx(0); // 2,560,000 cycles * 4MHz modemStartTone(1); Delay10KTCYx(0); // 2,560,000 cycles * 4MHz strcpypgm2ram(s_packet.message, ">Test Message from M0RJC tracker project"); aprsSendPacket(&s_packet); Delay10KTCYx(0); // 2,560,000 cycles * 4MHz Delay10KTCYx(0); // 2,560,000 cycles * 4MHz Delay10KTCYx(0); // 2,560,000 cycles * 4MHz strcpypgm2ram(s_packet.message, ":M0RJC :If you can read this it works. "); itoa(count++, buffer); strcat(s_packet.message, buffer); aprsSendPacket(&s_packet); Delay10KTCYx(0); // 2,560,000 cycles * 4MHz Delay10KTCYx(0); // 2,560,000 cycles * 4MHz Delay10KTCYx(0); // 2,560,000 cycles * 4MHz strcpypgm2ram(s_packet.message, ":M0RJC :Message Again. "); itoa(count++, buffer); strcat(s_packet.message, buffer); aprsSendPacket(&s_packet); modemRxMode(); Delay10KTCYx(0); // 2,560,000 cycles * 4MHz Delay10KTCYx(0); // 2,560,000 cycles * 4MHz } }
void tracking_profondeur(int vitesse) { int i = 0 ; Sens_Profondeur = !sens_rotation_profondeur ; Enable_Profondeur = 1 ; for(i=0;i<nb_pas_profondeur;i++) { Clock_Profondeur = 0; Delay10KTCYx(vitesse); Clock_Profondeur = 1; Delay10KTCYx(vitesse); if (sens_rotation_profondeur==SENS_HOR) position_moteur_profondeur ++ ; else if (sens_rotation_profondeur==SENS_TRIGO) position_moteur_profondeur -- ; } }
void tracking_azimut(int vitesse) { int i = 0 ; Sens_Azimut = sens_rotation_azimut ; Enable_Azimut = 1 ; for(i=0;i<nb_pas_azimut;i++) { Clock_Azimut = 0; Delay10KTCYx(vitesse); Clock_Azimut = 1; Delay10KTCYx(vitesse); if (sens_rotation_azimut==SENS_HOR) position_moteur_azimut ++ ; else if (sens_rotation_azimut==SENS_TRIGO) position_moteur_azimut -- ; } }
void main(void) { ADCON1 = 7; TRISAbits.TRISA0 = 0; while (1) { led = 1; Delay10KTCYx(50); led = 0; Delay10KTCYx(50); } }
void rtcInit(void) { StartI2C(); WriteI2C(0xD0); WriteI2C(0x00); WriteI2C(0x80); //CH = 1 Stop oscillator WriteI2C(0x48); //Minute WriteI2C(0x16); //Hour WriteI2C(0x03); //Tuesday WriteI2C(0x14); //14 WriteI2C(0x03); //March WriteI2C(0x17); //2017 StopI2C(); //Stop the I2C Protocol Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); //Have to start the Clock again StartI2C(); WriteI2C(0xD0); WriteI2C(0x00); WriteI2C(0x00); //start Clock and set the second hand to Zero StopI2C(); Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); Delay10KTCYx(250); }
void delays(int x){ if (MNML){ for(x;x>0;x--){ Delay10KTCYx(100); Delay10KTCYx(100); Delay10KTCYx(50); } } else{ for(x;x>0;x--){ Delay10KTCYx(100); } } }
void main(void) { unsigned int a; char *ptr; char str[3] = "LCD"; char str2[] = "MPLAB C18"; TRISD = 0x00; while(1) { Lcd_Clear(); Lcd_Set_Cursor(1,1); ptr = &str[0]; Lcd_Write_String(ptr); Lcd_Set_Cursor(2,1); ptr = &str2[0]; Lcd_Write_String(ptr); Delay10KTCYx(200); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("Developed By"); Lcd_Set_Cursor(2,1); Lcd_Write_String("Faintree"); Delay10KTCYx(200); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("something"); for(a=0; a<15; a++) { Delay10KTCYx(30); Lcd_Shift_Left(); } for(a=0; a<15; a++) { Delay10KTCYx(30); Lcd_Shift_Right(); } Lcd_Clear(); Lcd_Set_Cursor(2,1); Lcd_Write_Char('e'); Lcd_Write_Char('S'); Delay10KTCYx(300); } }
char menu(void) { static unsigned char position = 0; unsigned char item = 0; unsigned char i; while (1) { if (position == MENU_LENGTH) position = 0; for (i = 0; i < LCD_LINES; i++) { lcd_goto(i + 1, 1); item = (position + i > MENU_LENGTH - 1) ? 0 : position + i; if (i == 0) lcd_write_pgm("\002"); else lcd_write_pgm(" "); lcd_write_pgm(menu_items[item]); } position++; while (PORTEbits.RE2 == 1); Delay10KTCYx(255); } return 0; }
void DelayMS(unsigned long milliseconds) { unsigned long count; for(count = 0; count < milliseconds; count++) Delay10KTCYx(1); }
// Blink mode for testing void blink(void){ LEDA = 0; LEDB = 1; LEDC = 0; LEDD = 1; RA =0; RB =1; RC =0; RD =1; RE =0; RF =1; while(1){ LEDA ^= 1; LEDB ^= 1; LEDC ^= 1; LEDD ^= 1; RA ^= 1; RB ^= 1; RC ^= 1; RD ^= 1; RE ^= 1; RF ^= 1; Delay10KTCYx(100); } // End added loop }
void main() { ADCON1 = 0xFF; //Faz todos os canais AD TRISA = 0x01; //Faz somente o pino RA0 como entrada e o restante como saída TRISB = 0x00; //Faz toda a porta B como saída TRISC = 0x00; //Faz toda a porta A como saída PORTB = 0x00; //Zera toda a porta B T0CON = 0b11000100; /*Configura o Registrador T0CON TMR0ON = 1 -> Habilita o TIMER 0 T08BIT = 1 -> TIMER 0 no modo 8 bits T0CS = 0 -> Incremento pelo ciclo de máquina ...0,5us para o cristal de 8MHz. T0SE = 0 -> Incremento na orda de subida. PSA = 0 -> Prescale aplicado ao Timer 0 PS2 = 1, PS1 = 0 e PS0 = 0 -> Prescale = 1:32*/ INTCON = 0b10100000; /*Configura o registrador INTCON GIE = 1 (bit7) -> Habilita a interrupção global TMR0IE = 1 (bit 5)-> Habilita a interrupção do Timer 0 TMR0IF = 0 (bit 2)-> Flag de interrupção do Timer 0 desligado */ TMR0L = 100; //Valor Inicial para o timer 0 ADCON2 = 0b10100001; /*ADFM1 = 1 -> Resultado da conversão AD ... justificado à direita - ****Velocidade de aquisição em 8TAD ACQT2 = 1 ACQT1 = 0 ACQT0 = 0 ****Fonte de clock em Fosc/8 ADCS2 = 0 ADCS1 = 0 ADCS0 = 1*/ ADCON1 = 0b00001110; //Configura o PINO RA0 como entrada analógica while(1) { ADCON0 = 0b00000001; /*Seleciona Canal 0 para conversão ...e habilita o conversor AD*/ ADCON0bits.GO = 1; //Inicializa a conversão while(ADCON0bits.GO); //Aguarda o término da conversão res_ad = ADRES; //atribui o valor convertido à variável res_ad0 tensao = (res_ad*5000) / 1023; //Calcula o valor em mV para o resultado obtido d1 = tensao / 1000; d2 = (tensao / 100) % 10; d3 = (tensao / 10) % 10; Delay10KTCYx(100); //Gera um delay de 500ms } }
void delay(){ char i = 0; for( i = 0; i < 10; i++ ) { Delay10KTCYx(41); // Delay of 320 000 cycles } }
void xpl_print_header(enum XPL_MSG_TYPE type) { // We should leave 50ms between two messages // If xpl_rate_limiter == time_ticks, then we have already sent a message recently // so we need to wait a bit. //if (xpl_rate_limiter == time_ticks) { // 50 ms @ 32 MHz == 40e4 cycles Delay10KTCYx(40); //} // Note: for the time being, we wait here 50 ms every time we send a packet. Start with simple code, // improve when required. printf("xpl-"); if (type == STAT) { printf("stat", xpl_instance_id); } else { printf("trig", xpl_instance_id); } printf("\n{\nhop=1\nsource=hollie-"); printf(XPL_DEVICE_ID); printf(".%s\ntarget=*\n}\n", xpl_instance_id); //xpl_rate_limiter = time_ticks; }
//main function void main(void) { unsigned char st1[]="STARTING"; unsigned char st2[]="."; //pins for drive LCD TRISB = 0x80; //Initialize modules Init_LCD(); i2c_config(); set_ds1307_time(AM,0,0,6); set_ds1307_day(8,11,8,13); lcd_putstr(st1); for(i=0;i<7;i++) { lcd_putstr(st2); Delay1KTCYx(200); } LCD_CMD(LCD_clear); while(1) { lcd_gotoxy(1,1);//hang 1, cot 1. Display_time(get_ds1307_time()); lcd_gotoxy(1,2);//hang 2, cot 1 Display_day(get_ds1307_day()); Delay10KTCYx(70); }; }
//------------------------------------------------------------------------------ void ubxReadShortMessage(void) { unsigned int sms_no = 301; char *ptr, buf[20]; do { if(sms_no > 330) break; sprintf(buf, (const far rom char*)"AT+CMGR=%d\r", sms_no); SerialWriteString(buf); // wait for response if (RX_TMOUT_ERR == WaitResp(500, 5)) return; // check response if(IsStringReceived("+CMGR")) { ptr = strstrrampgm(comm_buf, (const rom far char *)"+CMGR"); ptr = strchr(ptr, '\n') + 1; *(ptr + 6) = 0; (*sms_handler_ptr)(ptr); } sms_no++; Delay10KTCYx(100); }while(ubxIsShortMessageReceived() == UBX_SMS_S_RECEIVED); // delete all read messages SerialWriteRomString("AT+CMGD=1,1\r"); // wait response WaitResp(500, 5); }
void delay_1Sx(int n){ for(int i =0; i<n; i++){ for(int counter = 0; counter<16; counter++){ Delay10KTCYx(250); // Delay 2,500,000 Cycles = 0.0625 seconds } } }
void receiverMain() { int i; char offset; char status; //doCycle(); //doOscillate(); nrf_init(); delay(); nrf_rxmode(); delay(); Delay10KTCYx(100); offset = 0; STATUS_LED = 0; while(1) { //STATUS_LED = nrf_receive(&rx_buf); updateBuffer(); updateLEDs(); } }