Forum Replies Created
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
sai
Participantwhy we will use sbit is that mandatory?
April 12, 2014 at 11:40 am in reply to: MICRO CONTROLLER BASED ULTRASONIC DISTANCE MEASUREMENT SYSTEM #11536sai
Participantcan any one explin me about this code to measure distance in mm using 3 pin ultrasonic sensor…plz…#include<reg51.h>#include<intrins.h>#include<lcd_busy.h>#define lcd_port P1bit rec_flag=0;bit data_flag=0;void lcd_dispaly();void int_char_con(void);void serial_init();unsigned char array[5],count=0,dis_count=0;unsigned char rec=0;unsigned int dis=0,rot_count=0,ror_flag=0,step=0;unsigned int dis_array[10],direction_count=0,loop_count=0;unsigned int THOUSANDS,HUNDREDS, TENS, UNITS, DISTANCE, TEMP_VAL;////////////////////////////////void main(){// buzzer=0;lcd_init();lcd_init();serial_init();serial_init();message(0x80,”Ultrasonic target”);delay(500);init(0x01);while(1){if(data_flag==1){ES=0;rec_flag=0;data_flag=0;DISTANCE=array[1]*256+array[2];lcd_dispaly();delay(5);count=0;ES=1;}}}//////////////////////////void serial_init(){SCON=0X50; //SM2 SM1 SM0 REN TB8 RB8 TI RI G C/T M1 M0 G C/T M1 M0TMOD=0X20; //0010 0000 // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0TH1=0XFD; //9600TR1=1;EA=1;ES=1;}////////////////////////////void serial(void) interrupt 4{if(RI==1){RI=0;rec=SBUF;if(rec==0xff){rec_flag=1;}if(rec_flag==1){array[count++]=SBUF;if(count=)
data_flag=1;}}}/////////////////////////////////////////////void lcd_dispaly(){int_char_con();dis_count=0;}void int_char_con(void){init(0x80);THOUSANDS = DISTANCE/1000;//to get thousands numTEMP_VAL = DISTANCE%1000;HUNDREDS = TEMP_VAL/100; //to get hundreds numTEMP_VAL %= 100;TENS = TEMP_VAL/10; //to get tens numUNITS = TEMP_VAL%10;write_lcd(THOUSANDS+0x30);write_lcd(HUNDREDS+0x30);write_lcd(TENS+0x30);write_lcd(UNITS+0x30);} -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)