void main() { char txt[7]; Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off TRISB = 0b00010000; INTCON.GIE = 1; //Global Interrupt Enable INTCON.RBIF = 0; //Clear PORTB On-Change Interrupt Flag INTCON.RBIE = 1; //Enable PORTB On-Change Interrupt Lcd_Out(1,1,"Developed By"); Lcd_Out(2,1,"CELAB"); Delay_ms(3000); Lcd_Cmd(_LCD_CLEAR); T1CON = 0x10; //Initializing Timer Module while(1) { TMR1H = 0; //Sets the Initial Value of Timer TMR1L = 0; //Sets the Initial Value of Timer PORTB.F0 = 1; //TRIGGER HIGH Delay_us(10); //10uS Delay PORTB.F0 = 0; //TRIGGER LOW while(!PORTB.F4); //Waiting for Echo T1CON.F0 = 1; //Timer Starts while(PORTB.F4); //Waiting for Echo goes LOW T1CON.F0 = 0; //Timer Stops a = (TMR1L | (TMR1H<<8)); //Reads Timer Value a = a/58.82; //Converts Time to Distance a = a + 1; //Distance Calibration\ if(a>=2 && a<=400) //Check whether the result is valid or not { IntToStr(a,txt); Ltrim(txt); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Distance = "); Lcd_Out(1,12,txt); Lcd_Out(1,15,"cm"); } Delay_ms(400); } }
void CLocalSetAdd::OnOK() { const int NOFIND=-1; UpdateData(); if ( ! (m_name.Find("'") == NOFIND && m_name.Find(";") == NOFIND && \ m_remark.Find("'") == NOFIND && m_remark.Find(";") == NOFIND && ! m_name.IsEmpty()) ) AfxMessageBox("输入的文字中不能含用单引号及分号等特殊字符"); strSql.Format("Insert into lsq_reside_local ( llocal,lname,lremark) values( \ (select Ltrim(to_char(NVL(max(llocal),0)+1,'009')) from lsq_reside_local),\ '%s','%s' ) ",m_name,m_remark); if( COtherDecharge::WriteSQL(strSql) )AfxMessageBox("新增成功"); else AfxMessageBox("新增失败..."); CDialog::OnOK(); }
//----------------------------------------------------------------------- //Name: - Senior Design Project of Counting the Crowd entering the // Jamaraat area during the Hajj. // - PIC16F628a#3 is uesd as a storage unit to store and sent the // calculated echo pulses of Ultrasonic sensor to the Arduino // Uno R3. // - Assuming a room temp of 25 degrees centigrade. //Autor: Ahmed Abdulaziz Abualsaud //Version: v 1.0 //Date: Dec, 2, 2015 //----------------------------------------------------------------------- void main() { //Declare teh Global Variable int a; //Variable to store the echo pulses int i = 1; //Counter to know which sensor is selected char txt[7]; //Char String is used to send the distance to the Arduino char txtD[7];//Char String is used to send the selected sensor to the Arduino //Configure all pin as digital by disable the comparators CMCON = 0b00000111; //Configure the TIMER1 to work beasd on the internal oscilator speed 4MHz T1CON = 0b00000000; //Configure each digital bins as In/Out ports //Pin Name - 0/1 - Pin Lable - Pin Number TRISA.F0 = 0;// = exP3 - 17 TRISA.F1 = 0;// = stP3 - 18 TRISA.F4 = 1;// = done - 3 TRISB.F0 = 1;// = enP3(A1) - 6 TRISB.F1 = 1;// = Read3 - 7 TRISB.F2 = 0;// = MX3 - 8 TRISB.F4 = 1;// = C - 10 TRISB.F5 = 1;// = D - 11 UART1_Init(9600);// Initialize UART module at 9600 bps Delay_ms(50); // Wait for UART module to stabilize while (1) { //Clear the TIMER1 registers TMR1H = 0; TMR1L = 0; PORTA.F0 = 0; //Disable exP3 signal PORTA.F1 = 0; //Disable stP3 signal while(!PORTB.F1); //Wait the echo (Read3 signal) to become 1 T1CON.F0 = 1; //Enable the TIMER1 while(PORTB.F1); T1CON.F0 = 0; a = (TMR1L | (TMR1H << 8)) / 29.1 / 2; IntToStr(a,txt); Ltrim(txt); IntToStr(i,txtD); Ltrim(txtD); //Wait the control Signal from Arduino to start sending the data while(PORTB.F5 != 1 && PORTB.F4 != 0);//D&C while(PORTB.F0 == 0); //Wait for enP3 signal comming from Arduino PORTA.F1 = 1; //Enable stP3 signal // Start sending data via UART UART1_Write_Text("GG3_"); UART1_Write_Text(txtD); UART1_Write_Text(": "); UART1_Write_Text(txt); UART1_Write_Text(" cm"); UART1_Write_Text("!"); UART1_Write(13); //The Carriage Return PORTA.F0 = 1; //Enable the exP3 signal ++i; //Increment the sensor iterator if (i == 5){i = 1;} //Reset the sensor iterator while(PORTA.F4 == 0); //Wait for the done signal coming from Arduino }//End while loop }//End void main