Sie sind auf Seite 1von 16

berminat sila hubungi :morak Abe Yie : 0129683136 SMK Desa cemerlang, No.

1 jln Kenanga 1, Tmn Desa Cemerlang, 81800 Ulu Tiram, Joh or clicksor Your account (account id: 100-P-215749) has been created! Account ID: 100-P-215749 Password: zzzzzz 097780106 Publisher Account ID: 100-P-215749 New Password: edesjz 1laskopek hyehnyi035041 repot 1-2180679805 ni banner <script type="text/javascript"> //interstitial ad clicksor_enable_inter = true; clicksor_maxad = -1; clicksor_hourcap = -1; clicksor_showcap = 3; //connect widget clicksor_adhere_opt = 'left:50%'; //default pop-under house ad url clicksor_enable_pop = true; clicksor_frequencyCap = -1; durl = '';//default banner house ad url clicksor_default_url = ''; clicksor_banner_border = '#ffffff'; clicksor_banner_ad_bg = '#FFFFFF'; clicksor_banner_link_color = '#000000'; clicksor_banner_text_color = '#666666'; clicksor_banner_image_banner = true; clicksor_banner_text_banner = true; clicksor_layer_border_color = ''; clicksor_layer_ad_bg = ''; clicksor_layer_ad_link_color = ''; clicksor_layer_ad_text_color = ''; clicksor_text_link_bg = ''; clicksor_text_link_color = ''; clicksor_enable_text_link = true; clicksor_layer_banner = false; </script> <script type="text/javascript" src="http://ads.clicksor.com/showAd.php?nid=1&amp ;pid=215749&amp;adtype=1&amp;sid=347447"></script> <noscript><a href="http://www.yesadvertising.com">affiliate marketing</a></noscr ipt>

ni pop up <script type="text/javascript"> //default pop-under house ad url clicksor_enable_pop = true; clicksor_adhere_opt='left';

clicksor_frequencyCap =0.1; durl = ''; clicksor_layer_border_color = ''; clicksor_layer_ad_bg = ''; clicksor_layer_ad_link_color = ''; clicksor_layer_ad_text_color = ''; clicksor_text_link_bg = ''; clicksor_text_link_color = ''; clicksor_enable_inter=true; </script> <script type="text/javascript" src="http://ads.clicksor.com/newServing/showAd.p hp?nid=1&amp;pid=215749&amp;sid=347447"></script> <noscript><a href="http://www. yesads.com">online marketing</a></noscript>

Please write down your account info or print this page for future reference. 0x05,0x01, 0x09,0x04, 0xa1,0x01, 0x05,0x09, 0x19,0x01, 0x29,0x18, 0x15,0x00, 0x25,0x01, 0x75,0x01, 0x95,0x18, 0x81,0x02, 0x05,0x02, 0x09,0xbb, // // // // // // // // // // // // // ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; USAGE_PAGE (Generic Desktop) USAGE (Joystick) COLLECTION (Application) USAGE_PAGE (Button) USAGE_MINIMUM (Button 1) USAGE_MAXIMUM (Button 24) LOGICAL_MINIMUM (0) LOGICAL_MAXIMUM (1) REPORT_SIZE (1) REPORT_COUNT (24) INPUT (Data,Var,Abs) USAGE_PAGE (Simulation Controls) USAGE (Throttle) LOGICAL_MINIMUM (0) LOGICAL_MAXIMUM (4095) REPORT_SIZE (16) REPORT_count (3) INPUT (data,Var,Abs) END_COLLECTION

0x15,0x00, // 0x26, 0xFF, 0x0F, // 0x75,0x10, // 0x95,0x01, // 0x81,0x02, // 0xc0 //

0x05, 0x01, // 0x09, 0x04, // 0xa1, 0x01, // 0x09, 0x01,// 0xa1, 0x00, // 0x09,0xbb, // 0x09, 0x36, //

Usage Page 'Generic Desktop Controls' Usage 'Joystick' Collection 'Application (mouse, keyboard)' Usage 'Pointer' Collection 'Physical (group of axes)' Usage 'throtle' Usage slider

0x15, 0x32, // 0x15, 0x33, // 0x15, 0x34, // 0x15, 0x35 , // 0x15, 0x37 , // 0x15, 0x36 , // 0x15, 0x00 , // 0x26, 0xff, 0x0f, // 0x75, 0x10, // 0x95, 0x02, // 0x81, 0x02, // null-pos bit-field 0xc0 // 0x05, 0x09, // 0x19, 0x01, // 0x29,0x18, // 0x15, 0x00, // 0x25, 0x01, // 0x75, 0x01, // 0x95, 0x18, // 0x81, 0x02, // bit-field 0x05, 0x01, // 0x09, 0x39, // 0x25, 0x07, // 0x35, 0x00, // 0x46, 0x3b, 0x01, // 0x55, 0x00, // 0x65, 0x44, // ees) 0x75, 0x04, // 0x95, 0x01, // 0x81, 0x42 , // bit-field 0x65, 0x00, // 0x95, 0x01, // 0x75, 0x04 , // 0x81, 0x03, // os bit-field 0xa1, 0x02, // 0x06, 0x00, 0xff, // 0x09, 0x01, // 0x15, 0x00, // 0x26, 0xff, 0x00, // 0x75, 0x08, // 0x95, 0x11, // 0xb1, 0x02, // e null-pos non-vol bit-field 0xc0 // 0xc0 //

Logical Minimum = 50 Logical Minimum = 51 Logical Minimum = 52 Logical Minimum = 53 Logical Minimum = 55 Logical Minimum = 54 Logical Minimum = 0 Logical Maximum = 4095 Report Size = 16 Report Count = 2 Input data *var abs lin pref-state End Collection Usage Page 'Button' Usage Minimum = 1 Usage Maximum = 24 Logical Minimum = 0 Logical Maximum = 1 Report Size = 1 Report Count = 24 Input data *var abs lin pref-state null-pos Usage Page 'Generic Desktop Controls' Usage 'Hat switch' Logical Maximum = 7 Physical Minimum = 0 Physical Maximum = 315 Unit Exponent = 0 Unit = System(English-Rotation) Length(Degr Report Size = 4 Report Count = 1 Input data *var abs lin pref-state null-pos Unit = None Report Count = 1 Report Size = 4 Input *const *var abs lin pref-state null-p Collection 'Logical (interrelated data)' Usage Page 'Vendor-defined' Usage 1 Logical Minimum = 0 Logical Maximum = 255 Report Size = 8 Report Count = 17 Feature data *var abs lin pref-stat End Collection End Collection

0x05,0x01, 0x09,0x04, 0xa1,0x01, 0x05,0x09, 0x19,0x01,

// // // // //

; ; ; ; ;

USAGE_PAGE (Generic Desktop) USAGE (Joystick) COLLECTION (Application) USAGE_PAGE (Button) USAGE_MINIMUM (Button 1)

0x29,0x18, // 0x15,0x00, // 0x25,0x01, // 0x75,0x01, // 0x95,0x18, // 0x81,0x02, // 0xc0 // 0x05,0x02, // 0x09,0xbb, // 0x15, 0x32, 0x15, 0x33, 0x15, 0x34, 0x15, 0x35, 0x15, 0x37, 0x15, 0x36, 0x15, 0x00, 0x26, 0xFF, 0x0F, 0x75,0x10, // 0x95,0x01, // 0x81,0x02, // 0xc0 // 0xc0 //

; USAGE_MAXIMUM (Button 24) ; LOGICAL_MINIMUM (0) ; LOGICAL_MAXIMUM (1) ; REPORT_SIZE (1) ; REPORT_COUNT (24) ; INPUT (Data,Var,Abs) ; END_COLLECTION ; USAGE_PAGE (Simulation Controls) ; USAGE (Throttle) ; Logical Minimum = 50 ; Logical Minimum = 51 ; Logical Minimum = 52 ; Logical Minimum = 53 ; Logical Minimum = 55 ; Logical Minimum = 54 // ;logical Minumum (0) // ;logical Maximum (4095) ; REPORT_SIZE (16) ; REPORT_count (1) ; INPUT (data,Var,Abs) ; END_COLLECTION ; END_COLLECTION

0x05,0x01, // 0x09,0x04, // 0x09,0x04, // 0xA1,0x00, // 0x09,0x36, // 0x09,0x37, // 0x09,0x38, // 0x75,0x08, // 0x95,0x03, // 0x35,0x00, // 0x46,0xFF,0X00, // 0x81,0x03, // 0xa1,0x01, // 0x05,0x09, // 0x19,0x01, // 0x29,0x18, // 0x15,0x00, // 0x25,0x01, // 0x75,0x01, // 0x95,0x18, // 0x81,0x02, // 0xc0 //

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

USAGE_PAGE (Generic Desktop) USAGE (Joystick) USAGE (Joystick) COLLECTION (Physical) Usage (slider) usage(dial) usage(wheel) REPORT_SIZE (8) REPORT_count (3) PHYSICAL_MINIMUM (0) PHYSICAL_MAXIMUM (255) INPUT (cNST,Var,Abs) COLLECTION (Application) USAGE_PAGE (Button) USAGE_MINIMUM (Button 1) USAGE_MAXIMUM (Button 24) LOGICAL_MINIMUM (0) LOGICAL_MAXIMUM (1) REPORT_SIZE (1) REPORT_COUNT (24) INPUT (Data,Var,Abs) END_COLLECTION

0x05,0x01, 0x09,0x04, 0xa1,0x01, 0x05,0x09, 0x19,0x01, 0x29,0x18, 0x15,0x00,

// // // // // // //

; ; ; ; ; ; ;

USAGE_PAGE (Generic Desktop) USAGE (Joystick) COLLECTION (Application) USAGE_PAGE (Button) USAGE_MINIMUM (Button 1) USAGE_MAXIMUM (Button 24) LOGICAL_MINIMUM (0)

0x25,0x01, 0x75,0x01, 0x95,0x18, 0x81,0x02, 0x05,0x02, 0x09,0xbb, 0x15,0x81, 0x25,0x7f, 0x75,0x08, 0x95,0x01, 0x81,0x02, 0xc0

// // // // // // // // // // // //

; ; ; ; ; ; ; ; ; ; ; ;

LOGICAL_MAXIMUM (1) REPORT_SIZE (1) REPORT_COUNT (24) INPUT (Data,Var,Abs) USAGE_PAGE (Simulation Controls) USAGE (Throttle) LOGICAL_MINIMUM (-127) LOGICAL_MAXIMUM (127) REPORT_SIZE (8) REPORT_count (1) INPUT (data,Var,Abs) END_COLLECTION

program SERVO8_10000 '******************************************************************************* ** ' SERVO8_10000 by Warren Schroeder on October 3, 2006 ' Program successfully compiled using mikroBASIC 5.0.0.0 ' Tested on 16F877A @ 20MHz ' Servo8_10000 is a demonstration of managing 8 servos every 20ms with more ' than 13-bit position resolution without using inline assembler code. ' You can theoretically achieve 10,000 servo positions per servo if using ' 500us to 2500us range servos and a 20MHz oscillator. Any servo timing range ' is possible up to maximum of 2500us. ' ' Theory of operation is to give each servo an exact 2500us frame to do its ' position duty-cycle. The servo turns ON at the start of the 2500us frame, ' completes its duty-cycle, turns OFF, and then waits for the next frame. At ' the next 2500us frame a new servo is then turned ON and the cycle is repeated. ' Each of the 8 servos occupies a 2500us slot and refreshed sequentially. All ' 8 servos thus require 20ms to complete. At this point, we go back to the firs t ' servo and repeat this whole process. This method creates exact 20ms periods ' between same servo time frames, which is required for 50Hz servos. ' ' The example below assumes using servos with a timing range of 900us to 2100us ' Timer1 is setup for 0.2us per count (no prescaler @ 20MHz). Therefore, the mi n ' and max position values for this servo would be 4500 to 10,500. To acheive 90 ' degrees of motion, or 1500us, the formula is 1500 x 5 = 7500. ' ' ABOUT USING RX. ' To use RX with USART I recommend using the mB USART library commands. These ' commands do not implement the USART Interrupts and are ideal for this program. ' Put the USART_DATA_READY and USART_READ function in the two wait loops in the ' MAIN program. USART has a 2-byte buffer which will not fill up and is not ' affected by the Timer interrupts as long as you take advantage of reading it ' regularly. Using the two wait loops is the best time to check the RX buffer. '******************************************************************************* *** '1-8203942356 symbol T1_Switch = T1CON.TMR1ON symbol T1_Int_Flag = PIR1.TMR1IF symbol T1_Int_En = PIE1.TMR1IE

symbol T0_Int_Flag = INTCON.TMR0IF symbol T0_Int_En = INTCON.TMR0IE const IsEnabled = 1 const IsDisabled = 0 const IsSet = 1 const IsRst = 0 const IsOn = 1 const IsOff = 0 dim intflag as boolean dim servo as byte dim T1 as word absolute $0E dim T0 as byte absolute $01 dim pos as word[8] sub procedure interrupt If T0_Int_Flag = IsSet Then T0 = -196 cycle Clearbit(PORTB, servo) servo = inc(servo) And 7 Setbit(PORTB, servo) T1 = 0 - pos[servo] T1_Switch = IsOn T1_Int_Flag = IsRst T0_Int_Flag = IsRst Else Clearbit(PORTB, servo) T1_Switch = IsOff End If intflag = not(intflag) end sub main: TRISB = 0 OPTION_REG = $85 PORTB = 0 INTCON = $E4 T1CON = 0 For servo = 0 to 7 pos[servo] = 7500 Next servo intflag = False servo = 0 T1 = 0 - 4500 T1_Int_Flag = IsRst T1_Int_En = IsEnabled T1_Switch = IsOn T0 = -196 T0_Int_En = IsEnabled Setbit(PORTB, 0) While 1=1 While intflag = False nop Wend While intflag = True nop Wend Wend ' if Timer0 interrupt ' load Frame 196 x 12.8us = 2508us interrupt ' ' ' ' ' ' ' ' ' ' force servo off...in case value was wrong next servo turn on next servo load servo position...each count is 0.2us turn Timer1 On reset Timer1 Interrupt Flag reset Timer0 Interrupt Flag if Timer1 interrupt turn off servo turn Timer1 Off

' interrupt flag status

' Timer0 prescaler = 64 = 12.8us ' GIE, PEIE, Timer0 Enabled; Timer0 Flag Set ' Timer1 Off; No prescaler ' set for 1500us mid-point

' ' ' ' ' ' '

load Timer1 reset Timer1 Interrupt Flag Timer1 Interrupt Enabled Timer1 On load TMR0 for 2500us Interrupt Cycle Count reset Timer0 Interrupt Flag turn on first servo

' WAIT until Timer1 Interrupt ' place USART Read routines in here ' WAIT until Timer0 Interrupt ' place USART Read routines in here

end. -----------------------------------------------------------------------------------------------------------------------------------------------------------------http://www.microchipdirect.com/ProductSearch.aspx?keywords=TMIK002 Part Number: AC164110 - RJ-11 to ICSP Adapter Ayisha.Arshad@shell.com Hi, I am Nor Azam from Malaysia.I am only a school teacher. I have design a few project using Microchip microcontroller which help student, engineer or hobbyist to built D.I.Y racing cockpit. This project code can be download freely at htt p://simf1.blogspot.com/. I've been working about 6 month to improve and debug th e code. Unfortunately I've been working on very tight budget right now to buy a testing equipment and material. I very appreciate if Microchip can help me to h elp people using microchip product to built more advance project. Thanks in adva nce.. info@olimex.com Hi, Good morning to person which can help me. I am from Malaysia. I am writing this letter on behalf of simf1.blogspot.com. I have design a few project using micro chip microcontroller using easypic3 which help racer, gamers, student, engineer and hobbyist to built D.I.Y racing cockpit. This blog discuss about building a r acing simulator from software to cockpit construction. My blog has been visit by thousands of people which mostly racer engineer and automotive technician aroun d the world. Project code and schematic can be downloaded freely at http://simf1 .blogspot.com/. I've been working about 7 month to improve and debug the code. A s a teacher unfortunately I've been working on very tight budget right now to bu y a testing equipment and material. I really appreciate if mikroelektronika comp any can support my blog. As my appreciation to company I will give a good revie w and recommendation to my visitors. I will add mikroelektronika as a sponsor li nk in my web. At the moment I also receive programming equipment sponsored by ww w.microchip.com. Thank you in advance. Best wishes, Nor Azam Jaafar Admin of simf1.blogspot.com Dear sir, Madam I am from Malaysia. I am writing this letter on behalf of simf1.blogspot.com. I have design a few project using microcontroller which help student, engineer an d hobbyist to built D.I.Y simulator cockpit. This blog discuss about building a car and flight simulator from software to cockpit construction. My blog has been visit by thousands of people recently. Which mostly engineer, student and autom otive technician around the world. Project code and schematic can be downloaded freely at http://simf1.blogspot.com/. I've been working about 7 month to improve and debug the code. As a teacher at secondary school unfortunately I've been wo rking on very tight budget right now to buy a testing equipment and material. At the moment I am designing a pendulum inverted project using rc car. I really a ppreciate if Segway Inc.can support my blog. As my appreciation to company I w ill give a good review and recommendation to my blog visitors. I will add Segway

Inc. as a sponsor link in my web. I really appreciate if you can forward this e-mail to sponsorship department. Thank you in advance. Best wishes, Nor Azam Jaafar a.k.a kubing Administrator of simf1.blogspot.com 1-8002223574 I am Nor Azam from Malaysia. I am only a school teacher. I have design a few ele ctronic project using microcontroller which help student, engineer or hobbyist t o built D.I.Y racing cockpit and robotic related. This project code and circuit can be download freely at http://simf1.blogspot.com/. I've been working about 8 month to improve and debug the code. Unfortunately I've been working on very t ight budget right now to buy a testing equipment and material. I very appreciate if SABIC can help me to help people built more advance project. Your donation I nsyaallah will be use to buy a few equipment and relate material. Your concern i s highly appreciated. Thanks in advance.. Hi, Good morning Sir. I am from Malaysia. I am writing this letter on behalf of sim f1.blogspot.com. I have design a few project using microcontroller which help ra cer, gamers, student, engineer and hobbyist to built D.I.Y racing cockpit. This blog discuss about building a racing simulator controller. My blog has been visi t by thousands of people which mostly hardcore gamer, racer engineer and automot ive technician around the world. Project code and schematic can be downloaded fr eely at http://simf1.blogspot.com/. I've been working about 7 month to improve a nd debug the code. As a teacher unfortunately I've been working on very tight bu dget right now to buy a testing equipment and material. I really appreciate if O penWheeler company can give a little support to my blog. As my appreciation to c ompany I will give a good review and recommendation to my visitors to use your product. I will add OpenWheeler as a sponsor link in my web. Best wishes, Nor Azam Jaafar Admin of simf1.blogspot.com Hi Shino, Remember me? I am admin of simf1.blogspot.com. just drop an email to say Hi to y ou. Good day and don't forget to visit my blog.

Best wishes, Nor Azam Jaafar Admin of simf1.blogspot.com /* * Project name: UART (Simple usage of UART module library functions) * Copyright: (c) Mikroelektronika, 2009. * Revision History:

20080930: - initial release; - 20090720 - modified by Slavisa Zlatanovic; * Description: This code demonstrates how to use uart library routines. Upon receiving data via RS232, MCU immediately sends it back to the sender. * Test configuration: MCU: PIC16F887 http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf dev.board: easypic6art http://www.mikroe.com/eng/products/view/297/easypic6-devel opment-system/ Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC PRO for PIC http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-p ic/ * NOTES: - RX and TX UART switches on EasyPIC6 should be turned ON (SW7.1 and SW8.1) . */ char uart_rd; void main() { ANSELB = 0; C1ON_bit = 0; C2ON_bit = 0; trisb = 0 ; portb = 0b00000001; UART1_Init(19200); Delay_ms(100); while (1) { if (UART1_Data_Ready()) { uart_rd = UART1_Read(); portb = uart_rd ; uart1_write(uart_rd); /*latb.b0 = 0; // RB0 = 0 Delay_Ms(500); // Wait 1 second latB.b0 = 1; // RB0 = 1 Delay_Ms(500); // Wait 1 second latb.b0 = 0; // RB0 = 0 Delay_Ms(400); // Wait 1 second latB.b0 = 1; // RB0 = 1 Delay_Ms(400); // Wait 1 second latb.b0 = 0; // RB0 = 0 Delay_Ms(200); // Wait 1 second latB.b0 = 1; // RB0 = 1 Delay_Ms(200); // Wait 1 second } } }

// Disable comparators

// Initialize UART module at 9600 bps // Wait for UART module to stabilize // Endless loop // If data is received, // read the received data,

*/

http://www.bkprecision.com/products/model/1900/1-16v-60a-switching-dc-power-supp

ly.html (230 Vac European version) http://www.bkprecision.com/products/model/316/mini-ac-dc-clamp-meter.html http://www.bkprecision.com/products/model/390A/test-bench-dmm-with-protective-ru bberized-case-and-usb-interface.html http://www.bkprecision.com/products/model/4011A/5-mhz-function-generator.html (2 30 Vac European version)

/* * Project name: Timer0_Interrupt (Using Timer0 to obtain interrupts) * Copyright: (c) Mikroelektronika, 2008. * Revision History: 20080930: - initial release; * Description: This code demonstrates how to use Timer0 and it's interrupt. Program toggles LEDs on PORTB. * Test configuration: MCU: PIC16F1937 http://ww1.microchip.com/downloads/en/DeviceDoc/41364B.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/eng/products/view/297/easypic6-devel opment-system/ Oscillator: HS, 08.0000 MHz Ext. Modules: SW: mikroC PRO for PIC http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-p ic/ * NOTES: - Turn on LEDs on PORTB switch SW9.2 (board specific). */ unsigned cnt; void interrupt() { if (TMR0IF_bit) { cnt++; TMR0IF_bit = 0; TMR0 = 96; } if (cnt >= 50) { latb.b0 = ~latb.b0 ; // Toggle PORTB LEDs cnt = 0; // Reset cnt } } void main() { OPTION_REG = 0x84; ANSELA = 0; ANSELB = 0; ANSELD = 0; ANSELE = 0; C1ON_bit = 0; C2ON_bit = 0; TRISB = 0; // Assign prescaler to TMR0 // Configure AN pins as digital

// increment counter // clear TMR0IF

// Disable comparators // PORTB is output

PORTB = 0; TMR0 = 96; INTCON = 0xA0; cnt = 0; // do { // if (cnt >= 400) { // PORTB = ~PORTB; // cnt = 0; // } // } while(1); }

// Initialize PORTB // Timer0 initial value // Enable TMRO interrupt // Initialize cnt

// Toggle PORTB LEDs // Reset cnt

ADCIN0 = adc_read(0)

; // 'error

DIFF0 = SERVOPOS0 - adcin0 /4 ;

adcin1 = adc_read(1) ; //' read analog value from ra1 DIFF1 = SERVOPOS1 - adcin1/4 ; //'error adcin2 = adc_read(2) ; // read analog value from ADC module channel 2

DIFF2 = SERVOPOS2 - adcin2/4 ;// 'error

double val; int rounded_val; rounded_val = (int) (val + 0.5); I tried it to run on 877. First it asks Press button to start when pressed it st acks at the point where LCD displays 'Distance Measuring'. What is wrong? sbit sbit sbit sbit sbit sbit LCD_RS LCD_EN LCD_D4 LCD_D5 LCD_D6 LCD_D7 at at at at at at RB4_bit; RB5_bit; RB0_bit; RB1_bit; RB2_bit; RB3_bit; at at at at at at TRISB4_bit; TRISB5_bit; TRISB0_bit; TRISB1_bit; TRISB2_bit; TRISB3_bit;

sbit LCD_RS_Direction sbit LCD_EN_Direction sbit LCD_D4_Direction sbit LCD_D5_Direction sbit LCD_D6_Direction sbit LCD_D7_Direction // LCD Baglantilari

sbit BUTT at RD1_bit; sbit ADGD at GO_DONE_bit; // go/done bit of the ADC control register 0 char txt1[] = "Microcontrollers";

char char char char char char char char char

txt2[] = "Project"; txt3[] = "Distance"; txt4[]=""; txt5[] = "Measuring"; txt6[] = "Too Far!"; txt7[] = "Press Button"; txt8[] = "For Measuring"; txt9[] = "Ultrasonic"; txt10[] = "Distance Meter";

#define PWM PORTC unsigned char read_button = 1, small_delay = 0, pwm_number; // kontrol degiskenl eri unsigned char button_1 = 0; unsigned char button_2 = 0; unsigned char start = 0; unsigned char button_p = 0; // RA1 tusunun gecerli ve nceki durumu unsigned char *dot_order; // address of character '.' in string unsigned char ADHIGH, ADLOW, consec_counter = 0, k = 0; // AD cevirimi icin degi skenler unsigned int i, j, m = 1, treshold, subtract, consecutive; // kontrol degiskenle ri unsigned int timer_val; // TIMER1 degeri unsigned int voltage_val; // AD cevirimi sunucu float result = 0, result_avg = 0; // cm olarak uzaklk void InitPort(void) { // I/O Portlarn belirlenmesi ANSEL = 0x01; // pin RA0 is analog ANSELH = 0x00; // other pins are digital I/O PWM = 0x00; // default value of PORTC TRISC = 0x00; // set PORTC as output TRISA = 0xFF; // set PORTA as input TRISD = 0x02; // set PORTD1 as input } void InitADC(void) { // function for initialization of AD Converter ADCS1_bit = 1; // set Fosc/32 as conversion clock ADCS0_bit = 0; // conversion time is approx. 44 us ADFM_bit = 1; // right justified result ADON_bit = 1; // enable ADC } void InitTimer(void) { // function for initialization of TIMER1 TMR1ON_bit=0; TMR1H = 0x00; // reset the value of timer registers TMR1L = 0x00; T1CKPS1_bit = 1; // set prescaler to 4 T1CKPS0_bit = 0; // TIMER1 counts every 2 us } void BEGIN(void) { Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,txt1); // Write text in first row Lcd_Out(2,5,txt2); // Write text in second row Delay_ms(2500); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,4,txt9); // Write text in first row Lcd_Out(2,2,txt10); // Write text in second row

Delay_ms(2500); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1,3,txt7); Lcd_Out(2,2,txt8); button_2=1; RD1_bit=0; } void main() { InitPort(); // initialization of PORTS InitADC(); // initialization of AD Converter InitTimer(); Lcd_Init(); if (start == 0) { if (button_2 == 0) { BEGIN(); } else goto bgn; } else{ goto measure; } bgn: while(1) { if (read_button == 1) { button_1 = BUTT; // read state of button RA1 if ((button_1 != button_p) && (button_1 != 0)){ // if it's pressed Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1,5,txt3); // Write text in first row Lcd_Out(2,4,txt5); // Write text in second row Delay_ms(250); read_button = 0; // and reset control variable button_p = button_1; // save present state of the button start=start+1; goto measure; } } measure:{ while (read_button == 0) { TRISC2_bit = 0; // set pin RC2 as output TMR1ON_bit = 1; // start TIMER1 PWM = 0x02; // 42 KHz PWM, 13 impulses Delay_us(8); for(pwm_number = 1; pwm_number <= 25; pwm_number++) { PWM ^= 0x06; small_delay = 0; Delay_us(7); } PWM = 0x00; Delay_us(50); TRISC2_bit = 1; // set pin RC2 as input voltage_val = 0; // set default values before consec_counter = 0; // next cycle of AD conversions timer_val = 0; k = 0; Delay_us(129); // time that piezo transducer needs to settle down

for(i = 0; i < 1953; i++) { ADGD = 1; // start AD conversion every 60 us, max number // of conversions is 1954 (distance of about 20 metres) if (i < 9) { // max 15 cm distance treshold = 512; // treshold is ~2.5 V consecutive = 5; // number of needeed consecutive voltages above the treshold subtract = 255; // value that needs to be substracted from TIMER1 registers } // in order to get calibrated value of distance else if (i < 22) { // max 30 cm distance treshold -= 4; // reduce treshold by ~20 mV each time a conversion consecutive = 6; // is done, treshold slowly drops to ~2.24 V subtract = 325; } else if (i < 70) { // max 80 cm distance treshold -= 2; // reduce treshold by ~10 mV each time a conversion consecutive = 6; // is done, treshold slowly drops to ~1.78 V subtract = 300; } else if (i < 180) { // max 193 cm distance if (k == 4) { // reduce treshold by ~5 mV after 4 consecutive conversions, treshold -= 1; // treshold slowly drops to ~1.65 V k = 0; } else k++; consecutive = 8; subtract = 300; } else if (i < 250) { // max 265 cm distance consecutive = 10; subtract = 315; } else { // distance greater than 265 cm consecutive = 10; subtract = 220; } voltage_val = 0; voltage_val = (ADHIGH << 8) + ADLOW; // read the value of previous conversion if (voltage_val > treshold) // check if the voltage is greater that the treshold , consec_counter++; // and if it is, increment the counter of consecutive else // voltages greater than the treshold consec_counter = 0; if (consec_counter == consecutive) { // if adequate number of consecutive voltag es greater TMR1ON_bit = 0; // than the treshold is detected, stop TIMER1 timer_val = 0; // and save values of timer registers timer_val = TMR1H << 8; timer_val &= 0xFF00; timer_val = TMR1L; timer_val -= subtract; break; // exit ADC loop } else { while(ADGD == 1) { // wait for conversion to be done }

ADHIGH = ADRESH; // get the result of conversion ADLOW = ADRESL; Delay_us(4); } } if (timer_val != 0) { if (timer_val < 199) // limit the minimal value that can be detected timer_val = 199; // (7 cm) result = (float)timer_val * 0.034; // calculate the distance in centimetres result_avg += result; if (j == 4) { // calculate the average value j = 1; // of 4 consecutive measurements result_avg /= 4; FloatToStr(result_avg, txt4); // convert the result in string dot_order = strrchr(txt4, '.'); // round the result if (*(dot_order + 1) < '2') { // and display only 1 digit *(dot_order + 1) = '0'; // behind the decimal point } else if (*(dot_order + 1) == '2') { if (*(dot_order + 2) < '6') { *(dot_order + 1) = '0'; } else { *(dot_order + 1) = '5'; } } else if (*(dot_order + 1) < '7') { *(dot_order + 1) = '5'; } else if (*(dot_order + 1) == '7') { if (*(dot_order + 2) < '5') { *(dot_order + 1) = '5'; } else { result_avg += 1; FloatToStr(result_avg, txt4); dot_order = strrchr(txt4, '.'); *(dot_order + 1) = '0'; } } else { result_avg += 1; FloatToStr(result_avg, txt4); dot_order = strrchr(txt4, '.'); *(dot_order + 1) = '0'; } *(dot_order + 2) = '\0'; strcat(txt4, " cm "); // add text to string result_avg /= 6.25; Lcd_Out(1,5,txt3); // Write text in first row Lcd_Out(2,5,txt4);

result_avg = 0; Delay_ms(40); } else { j++; Delay_ms(48); } } else { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,5,txt3); Lcd_Out(2,6,txt6); // Write text in second row Delay_ms(48); } InitTimer(); // initialize TIMER1 for new cycle of AD conversions } } } } Report this post Dear sir, Madam We are from Malaysia. Writing this letter on behalf of simf1.blogspot.com. we h ave design a few project using microcontroller which help student, engineer and hobbyist to built D.I.Y simulator cockpit. This blog discuss about building a ca r and flight simulator from software to cockpit construction. Our blog has been visit by thousands of people recently. Which mostly engineer, student and automo tive technician around the world. Project code and schematic can be downloaded f reely at http://simf1.blogspot.com/. We've been working about 11 month to improv e and debug the code. At the moment we built real time FPV cockpit for real time uav control. We really appreciate if Vuzix Corporation can support our blog. A s appreciation to company we will give a good review and recommendation to our blog visitors about your product. We will add Vuzix Corporation as a sponsor lin k in our web. We really appreciate if you can forward this e-mail to sponsorshi p department. Thank you in advance. Best wishes, Kubing and Group members Administrator of simf1.blogspot.com

Das könnte Ihnen auch gefallen