This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

LinkLabel trong C#

LinkLabel trong C#



A LinkLabel control is a label control that can display a hyperlink. A LinkLabel control is inherited from the Label class so it has all the functionality provided by the Windows Forms Label control. LinkLabel control does not participate in user input or capture mouse or keyboard events. 

In this article, I will discuss how to create a LinkLabel control in Windows Forms at design-time as well as run-time. After that, I will continue discussing various properties and methods available for the LinkLabel control. 

In Visual Studio 2010, the ToolStripLabel control is recommended for a LinkLabel control.
Creating a LinkLabel
There are two ways to create a control.
Design-time
First, we can use the Form designer of Visual Studio to create a control at design-time. In design-time mode, we can use visual user interfaces to create a control properties and write methods.
To create a LinkLabel control at design-time, you simply drag and drop a LinkLabel control from Toolbox to a Form. After you drag and drop a LinkLabel on a Form. The LinkLabel looks like Figure 1. Once a LinkLabel is on the Form, you can move it around and resize it using mouse and set its properties and events.
LinkLabelImg1.jpg
Figure 1
Run-time
LinkLabel class represents a hyperlink Label control. We simply create an instance of LinkLabel class, set its properties and add this it to the Form controls.
In the first step, we create an instance of the LinkLabel class. The following code snippet creates a LinkLabel control object.
LinkLabel dynamicLinkLabel = new LinkLabel();

In the next step, we set properties of a LinkLabel control. The following code snippet sets background color, foreground color, Text, Name, and Font properties of a LinkLabel.
// Set background and foreground
dynamicLinkLabel.BackColor = Color.Red;
dynamicLinkLabel.ForeColor = Color.Blue;
         
dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
dynamicLinkLabel.Name = "DynamicLinkLabel";
dynamicLinkLabel.Font = new Font("Georgia", 16);

In the last step, we need to add a LinkLabel control to the Form by calling Form.Controls.Add method. The following code snippet adds a LinkLabel control to a Form.

Controls.Add(dynamicLinkLabel);  
Setting LinkLabel Properties
After you place a LinkLabel control on a Form, the next step is to set properties.
The easiest way to set properties is from the Properties Window. You can open Properties window by pressing F4 or right click on a control and select Properties menu item. The Properties window looks like Figure 2.
LinkLabelImg2.jpg
Figure 2
Name 
Name property represents a unique name of a LinkLabel control. It is used to access the control in the code. The following code snippet sets and gets the name and text of a LinkLabel control.
dynamicLinkLabel.Name = "DynamicLinkLabel";
string name = dynamicLinkLabel.Name;
Location, Height, Width, and Size 

The Location property takes a Point that specifies the starting position of the LinkLabel on a Form. The Size property specifies the size of the control. We can also use Width and Height property instead of Size property. The following code snippet sets Location, Width, and Height properties of a LinkLabel control.
dynamicLinkLabel.Location = new Point(20, 150);
dynamicLinkLabel.Height = 40;
dynamicLinkLabel.Width = 300;
Background, Foreground, BorderStyle
BackColor and ForeColor properties are used to set background and foreground color of a LinkLabel respectively. If you click on these properties in Properties window, the Color Dialog pops up.
Alternatively, you can set background and foreground colors at run-time. The following code snippet sets BackColor and ForeColor properties.
dynamicLinkLabel.BackColor = Color.Red;
dynamicLinkLabel.ForeColor = Color.Blue;
You can also set borders style of a LinkLabel by using the BorderStyle property. The BorderStyle property is represented by a BorderStyle enumeration that has three values – FixedSingle, Fixed3D, and None.  The default value of border style is Fixed3D. The following code snippet sets the border style of a LinkLabel to FixedSingle.
dynamicLinkLabel.BorderStyle = BorderStyle.FixedSingle;
Font 

Font property represents the font of text of a LinkLabel control. If you click on the Font property in Properties window, you will see Font name, size and other font options. The following code snippet sets Font property at run-time.
dynamicLinkLabel.Font = new Font("Georgia", 16);
Text and TextAlign, and TextLength 
Text property of a LinkLabel represents the current text of a LinkLabel control. The TextAlign property represents text alignment that can be Left, Center, or Right. The TextLength property returns the length of a LinkLabel contents.
The following code snippet sets the Text and TextAlign properties and gets the size of a LinkLabel control.
dynamicLinkLabel.Text = "I am Dynamic LinkLabel";
dynamicLinkLabel.TextAlign  HorizontalAlignment.Center;
int size = dynamicLinkLabel.TextLength;
Append Text 

We can append text to a LinkLabel by simply setting Text property to current text plus new text you would want to append something like this.
dynamicLinkLabel.Text += " Appended text";
AutoEllipsis
An ellipsis character (...) is used to give an impression that a control has more characters but it could not fit in the current width of the control. If AutoEllipsis property is true, it adds ellipsis character to a control if text in control does not fit. You may have to set AutoSize to false to see the ellipses character.
Image in LinkLabel 

The Image property of a
 LinkLabel control is used to set a LinkLabel background as an image. The Image property needs an Image object. The Image class has a static method called FromFile that takes an image file name with full path and creates an Image object.
You can also align image and text. The ImageAlign and TextAlign properties of Button are used for this purpose.
The following C# code snippet sets an image as a LinkLabel background. dynamicLinkLabel.Image = Image.FromFile(@"C:\Images\Dock.jpg"); dynamicLinkLabel.ImageAlign = ContentAlignment.MiddleRight;dynamicLinkLabel.TextAlign = ContentAlignment.MiddleLeft; dynamicLinkLabel.FlatStyle = FlatStyle.Flat;
Hyperlink Properties

Here are the hyperlink related properties available in the LinkLabel control.
Links and LinkArea 

A LinkLabel control can display more than one hyperlink. The Links property a type of LinkCollection represents all the hyperlinks available in a LinkLabel control. The Add method of LinkColleciton is used to add a link to the collection. The Remove and RemoveAt methods are used to remove a link from the LinkCollection. The Clear method is used to remove all links from a LinkCollection.
LinkArea property represents the range of text that is treated as a part of the link. It takes a starting position and length of the text.
The following code snippet ads a link and sets LinkArea and a link click event handler.
dynamicLinkLabel.LinkArea = new LinkArea(0, 22);
dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
Here is the code for the LinkLabel click event handler and uses Process.Start method to open a hyperlink in a browser.
private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    dynamicLinkLabel.LinkVisited = true;
    System.Diagnostics.Process.Start("http://www.c-sharpcorner.com");    
}
LinkColor, VisitedLinkColor, ActiveLinkColor and DisabledLinkColor 

LinkColor, VisitedLinkColor, ActiveLinkColor and DisabledLinkColor properties represent colors when a hyperlink is in normal, visited, active, or disabled mode. The following code snippet sets these colors.
dynamicLinkLabel.ActiveLinkColor = Color.Orange;
dynamicLinkLabel.VisitedLinkColor = Color.Green;
dynamicLinkLabel.LinkColor = Color.RoyalBlue;
dynamicLinkLabel.DisabledLinkColor = Color.Gray;

Summary

A LinkLabel control is used to display a hyperlink and can be used to click the hyperlink to open a URL.. In this article, we discussed discuss how to create a LinkLabel control in Windows Forms at design-time as well as run-time. After that, we saw how to use various properties and methods.

MSP430F55xx Development Kit

Giới thiệu

OverView.png
MSP430F55xx Development Kit là một sản phẩm được thiết kế riêng, chuyên dụng, dành cho họ vi điều khiển MSP430F5xx của Texas Instruments. Đây là dòng vi điều khiển với các tính năng vượt trội về siêu tiết kiệm năng lượng, tần số hoạt động cao, tích hợp nhiều tính năng trên một con chip duy nhất. Vi xử lý với kiến trúc RISC, thanh ghi 16-bit và các bộ tạo hằng số cho phép đạt hiệu quả thực thi mã lập trình cao nhất. Bộ tạo tần số dao động nội (DCO) cho phép thời gian chuyển từ chế độ tiết kiệm năng lượng sang chế độ hoạt động bình thường < 5us.
Ưu điểm vượt trội của MSP430F55xx Development Kit là khả năng có thể nạp lại chương trình mà không cần phải dùng mạch nạp hoặc một thiết bị nào khác. Trên kit tích hợp sẵn một cổng USB 2.0 cho phép người sử dụng nạp lại chương trình bằng cách chuyển đổi jump (BOOT) để thay đổi giữa chế độ nạp và chế độ hoạt động bình thường. Cổng USB đó cũng được dùng để kit giao tiếp với máy tính, thư viện lập trình API đã được cung cấp sẵn bởi Texas Instruments.
Các tính năng của MSP430F55xx Development Kit
  • 31 chân giao tiếp ngoại vi.
  • Dải điện áp cung cấp cho kit từ 4.5Vdc – 20Vdc.
  • 2 LED xanh – đỏ có thể điều khiển được. 1 LED báo nguồn.
  • 1 nút nhấn kết nối với chân I/O (P2.0) và 1 nút nhấn reset.
  • Nạp lại chương trình mà không cần mạch nạp hay một thiết bị nào khác.
  • Giao tiếp với máy tính thông qua chuẩn USB 2.0.
Các thành phần chính của MSP430F55xx Development Kit
  • Dây cáp và cổng USB.
  • Thạch anh 32768Hz.
  • 2 header kết nối đực hoặc cái.
  • IC ổn áp nguồn ASM1117 – 3.3v
  • MSP430F5510 với 4 timer 16-bit, bộ chuyển đổi ADC tốc độ cao (> 200ksps), bộ giao tiếp nối tiếp USCI, bộ nhân phần cứng, DMA, bộ đếm thời gian thực và 31 chân I/O.


Cài đặt phần cứng và phần mềm


Cài đặt phần mềm

USB Firmware Upgrade.png
Hai trình biên dịch phổ biến được sử dụng với MSP430 là IAR Embedded Workbench Kickstart và Code Composer Studio(CCS). Cả hai trình biên dịch này đều có bản miễn phí và trả phí. IAR Embedded Workbench cho phép biên dịch đoạn mã assembly với dung lượng mã không giới hạn và giới hạn 4kB mã nguồn C. CCS giới hạn dung lượng mã nguồn C với 16kB. Ngoài ra, còn một số trình biên dịch khác như MSPGCC, Rowley Crossworks. Các bài lab được viết cho kit sử dụng trình biên dịch IAR và CCS. Chương trình để nạp cho MSP430F5xx Development Kit là USB Firmware Upgrade, được phát triển bởi Texas Instruments. Giao diện chương trình được thiết kế đơn giản, chỉ cần chọn file sau khi biên dịch bởi IAR hoặc CCS (*.txt) và nhấn Upgrade. Giao diện chương trình được mô tả ở hình bên. Chương trình kết nối với kit thông qua driver cổng COM ảo. Driver đã được cài kèm theo trong bộ cài đặt của IAR và CCS. Hoặc nếu không có sẵn, driver có thể được tải về tại đây.


Cài đặt phần cứng

Hàn linh kiện
MSP430F55xx Development Kit được thiết kế để người dùng có được sự thuận tiện nhất khi sử dụng. Hai hàng chân kết nối ngoại vi với kit được để trống cho người sử dụng tùy ý chọn kiểu header muốn dùng. Trước khi có thể sử dụng, hai lược (đực hoặc cái) phải được hàn vào hai hàng chân của kit.
Kết nối thạch anh 32768Hz
MSP430F5510 tích hợp sẵn module Real-Time Clock (RTC) cho phép ứng dụng có thể hoạt động với tính năng thời gian thực. Để sử dụng tính năng này, 2 chân XIN/XOUT của bộ tạo dao động UCS (Unified Clock System) cần được cấp xung clock với tần số thấp như thạch anh 32768Hz. Khi chức năng RTC không được sử dụng, hai chân XIN/XOUT có thể được cấu hình để sử dụng như một chân I/O.


Làm quen với MSP430F55xx Development Kit



Làm quen

MSP430F55xx Development Kit đã được nạp sẵn chương trình nháy LED và đo nhiệt độ. Khi kết nối kit lần đầu tiên với máy tính thông qua cổng USB, 2 LED xanh - đỏ sẽ nháy, báo hiệu kit đã được cấp nguồn và hoạt động chính xác. Thông tin chi tiết về chương trình nháy LED được ghi ở mục Các ứng dụng demo.


Các ứng dụng demo

Tại lần sử dụng đầu tiên, để kích hoạt các ứng dụng demo, chuyển jump (BOOT) sang chế độ hoạt động bình thường như hình bên và kết nối với máy tính thông qua cổng USB. Nút nhấn S1 được sử dụng để chuyển từ chương trình nháy LED sang chương trình đo nhiệt độ và ngược lại. Mã nguồn IAR và CCS của chương trình có thể được tải về tại đây.
Chương trình nháy LED
Đảm bảo rằng hai LED xanh - đỏ đã được nối với P1.0 và P1.1 thông qua P1, P2 (shorting jumper). Kết nối dây cáp USB với máy tính. LED xanh và đỏ sẽ chớp nháy liên tục.
Chương trình đo nhiệt độ
Nhấn nút S1 để chuyển sang chương trình demo hiển thị nhiệt độ. Trong MSP430F5510 có tích hợp một module cảm biến nhiệt độ, cho phép theo dõi nhiệt độ bên trong chip. Chương trình này sử dụng module ADC 10-bit để lấy mẫu, tính toán chuyển sang giá trị độ C, F và gửi lên máy tính thông qua cổng USB, chuẩn giao tiếp CDC. Để hiển thị nhiệt độ trên máy tính cần có một chương trình giao tiếp với kit, nhận dữ liệu và hiển thị nhiệt độ. Hình bên mô tả giao diện chương trình connectMSP430temperature. Các bước để sử dụng chương trình:
  • Driver cần được phải cài sẵn.
  • Hệ điều hành Windows XP với .NET framework hoặc Windows Vista trở lên.
  • Chuyển kit sang chế độ hoạt động bình thường (Xem hình 3.3).
  • Kết nối kit với máy tính qua cổng USB.
  • Chọn cổng COM kết nối theo các bước sau: Click chuột phải vào Computer ! Manage ! Device manager ! Ports (COMand LPT). Xem cổng kết nối của: MSP-FET430UIF - CDC. Chọn cổng COM đó tại mục Serial Port của giao diện chương trình.
  • Nhấn nút Start để bắt đầu nhận dữ liệu.
  • Click vào nút Help để xem hướng dẫn chi tiết hơn.

Tạo ứng dụng Visual C++ đơn giản nhất để học C

Tạo ứng dụng Visual C++ đơn giản nhất để học C

Dưới đây là các bước để tạo một ứng dụng đơn giản trong Visual C++. Những hình minh họa là cho Visual C++ 2010 Express, tuy nhiên, những phiên bản khác như Visual Studio 2005/2008/2010, Visual C++ 2008 Express đều có thể áp dụng được (giao diện có thể hơi khác một tí).

Bước 1. Khởi động Visual C++ 2010 Express  

Bằng cách Start → Programs → Microsoft Visual Studio 2010 Express → Microsoft Visual C++ 2010 Express, giao diện của VS10 Express sẽ hiện ra như hình 1:
 
Hình 1

Bước 2. Tạo một ứng dụng rỗng (kiểu Win32)   

Với VS10 Express nói riêng và VS10 nói chung, ta có thể xây dựng được rất nhiều loại chương trình: chạy trên web, trên điện thoại thông minh, trên máy tính cá nhân,... Trên máy tính cá nhân cũng có nhiều loại chương trình: ứng dụng winform (vd: chương trình quản lý nhân sự), thư viện (các file DLL), ứng dụng console (có cửa sổ nền đen chữ trắng như màn hình DOS thời xưa),... Ứng dụng console lại có 2 kiểu: chạy trên nền .NET Framework (CLR Console Application) và chạy trên nền hệ điều hành Windows (Win32 Console Application).
Trong số các loại ứng dụng này, ứng dụng console là đơn giản nhất vì không làm việc nhiều với giao diện (không có nút nhấn, không có hộp thả xuống, không có các biểu tượng hình ảnh đẹp mắt,...), do đó, nó rất thích hợp cho những newbie (tân binh) mới chập chững bước vào thế giới lập trình. Do với mục đích là HỌC nên chỉ sử dụng những chức năng cơ bản nhất, không cần những tính năng của mạnh mẽ khi viết trên nền .NET Framework, do vậy tôi chọn kiểu Win32 Console Application.
- Để bắt đầu việc tạo một solution (tạm dịch thoáng là "ứng dụng") mới, ta có nhiều cách để làm.
Cách 1: File → New → Project.
Cách 2: nhấn tổ hợp phím Ctrl + Shift + N.
Cách 3: trong vùng Start Page (khi VS mới khởi động), kích vào New Project.
     
Hình 2
- Trong cửa sổ New Project, đầu tiên kích chọn loại ứng dụng là Win32 [1]Win32 Console Application [2], sau đó gõ tên và thư mục chứa ứng dụng [3]. Chú ý: nên kích chọn Create directory for solution [4] để VS tạo một thư mục có tên là tên của ứng dụng và sẽ đưa tất cả những tập tin liên quan vào thư mục này (để dể quản lý). Cuối cùng, kích nút OK.
 
Hình 3
- Cửa sổ tiếp theo (Win32 Application Wizard) không có gì quan trọng. Kích nút Next để tiếp tục.
 
Hình 4
- Trong cửa sổ cuối cùng, trước tiên phải cọn loại ứng dụng là Console applicaton [1], sau đó bỏ chọn mục Precompiled header [2], chọn Empty project [3] và kích nút Finish [4] để VS bắt đầu tạo khung ứng dụng kiểu Win32 Console "rỗng".
 
Hình 5
- Thành quả của bước này sẽ như hình dưới đây: một solution (ứng dụng) chỉ có 1 project (dự án) và trong dự án này chỉ có 4 thư mục rỗng. Công việc tiếp theo sẽ là đưa thêm gì đó vào cái khung rỗng này để có được một chương trình "chạy được" :-)
 
Hình 6

Bước 3. Thêm mới một tập tin mã nguồn C/C++   

Kích phải vào hàng thứ 2 trong cửa sổ Solution Explorer, chọn Add → New Item.
 
Hình 7
- Trong cửa sổ Add New Item, trước tiên, kích chọn ngôn ngữ của ứng dụng (là Visual C++) [1], sao đó chọn loại tập tin sẽ tạo (là C++ File) [2], nhập tên của tập tin [3] và kích nút Add để VS bắt đầu tạo tập tin C để "gắn" vào ứng dụng.
 
Hình 8

Bước 4. Viết mã và Biên dịch chương trình   

Kích đúp vào tập tin mới tạo sau đó nhìm vào phần trung tâm của Visual Studio, bạn sẽ thấy 1 vùng rỗng (tab) có tên là tên của tập tin (ở đây là ChaoC.cpp). Đây chính là nội dung của tập tin này. Tiếp theo, chúng ta sẽ viết một chương trình C đơn giản nhất vào đây. Chương trình chỉ có một công việc đơn giản là hiển thị một dòng chào mừng: "Chao C! Chao Visual C++ 2010 Express!". Nhập nội dung chương trình như hình dưới (vùng [1]) và kích chọn Build → Build Solution hoặc nhấn phím F6 để biên dịch chương trình. Kết quả biên dịch được hiển thị ở cửa sổ Output [2]. Liếc nhìn hàng cuối cùng của cửa sổ Outputthấy "1 succeeded, 0 failed" nghĩa là đã biên dịch thành công, sẵn sàng chạy chương trình :-)
 
Hình 9

Bước 5. Thực thi chương trình  

Kích chọn Debug → Start Debugging (hoặc nhấn phím F5) để thực thi (chạy) chương trình. Kết quả chỉ đơn giản là một dòng chữ chào mừng màu trắng trên nền đen.
 
Hình 10
Đến đây coi như xong viết xong một ứng dụng C đơn giản nhất trên Visual C++ 2010 Express. Để làm các bài tập khác về C, chỉ đơn giản thay đổi nội dung chương trình ở vùng [1] trong bước 3 (Viết mã và Biên dịch chương trình).
Chúc các bạn sinh viên có một sự khởi đầu suôn sẻ.
Chúc mọi người học lập trình vui :-)
Visual C++

mãi mãi một tình yêu

mãi mãi một tình yêu

Thủ thuật Blogspot - Tạo readmore


Thalointe xin giới thiệu đến các bạn thủ thuật tạo readmore, tiện ích này sẽ rút ngắn bài viết của bạn ở trang chủ, tạo cho blog của bạn gọn và đẹp hơn.



Vào Template - Edit HTML, Expand widget, tìm đến thẻ <data:post.body/> và thay nó bằng đoạn code sau:

<b:if cond='data:blog.pageType != &quot;item&quot;'>


<div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div>


<script type='text/javascript'>createSummaryAndThumb(&quot;summary<data:post.id/>&quot;);


</script>


<span class='rmlink' style='float:right;padding-top:20px;'>


<a expr:href='data:post.url'> &#187;&#187;&#160;&#160; read more</a></span>


</b:if>


<b:if cond='data:blog.pageType == &quot;item&quot;'><data:post.body/>


</b:if>

Ngoài ra bạn còn phải cho đoạn code dưới đây vào phần HEAD (<head> ... </head>) của template:


<script type='text/javascript'> var thumbnail_mode = &quot;no-float&quot; ; summary_noimg = 430; summary_img = 340; img_thumb_height = 100; img_thumb_width = 120; </script>


<script type='text/javascript'>


//<![CDATA[


function removeHtmlTag(strx,chop){


if(strx.indexOf("<")!=-1)


{


var s = strx.split("<");


for(var i=0;i<s.length;i++){


if(s[i].indexOf(">")!=-1){


s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);


}


}


strx = s.join("");


}


chop = (chop < strx.length-1) ? chop : strx.length-2;


while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++;


strx = strx.substring(0,chop-1);


return strx+'...';


}


function createSummaryAndThumb(pID){


var div = document.getElementById(pID);

Â

var imgtag = "";


var img = div.getElementsByTagName("img");


var summ = summary_noimg;


if(img.length>=1) {


imgtag = '<span style="float:left; padding:0px 10px 5px 0px;"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></span>';


summ = summary_img;


}


var summary = imgtag + '<div>' + removeHtmlTag(div.innerHTML,summ) + '</div>';


div.innerHTML = summary;


}


//]]>


</script>

đưa file PDF lên blogger


Giáo trình AVR

L & C Meter (PIC16F84A based)

L & C Meter (PIC16F84A based)

No self respecting electronics experimenter these days should be without an LC (inductance/capacitance) measuring meter.
There are several good designs around; I can thoroughly recommend the product of "electronics - diy" in New York.
If you have a need for such a device I suggest you buy theirs immediately!
Its good value for money, compact, easy to use etc.
The website you need is:

"electronics - DIY.com" 

Additionally they will also supply various sections, to allow an experimenter to construct his own
This is exactly what I did, I purchased the pre programmed PIC microcontroller (for abt $US7) and used recycled componentry locally sourced the rest of the electronic hardware.
The enclosure is a metal box salvaged from discarded PC towers, being the switch mode power supply of the computer.
Simply remove the internals (circuit board, fan etc) and you have a 6" x 6" x 3" sized metal box with IEC mains entry connector - ready for re-use.
Blank off any larger holes with scrap metal material.
I have used wire-wrap sockets mounted on a s.r.b.p. (synthetic resin bonded paper) matrix board to facilitate construction of the "electronics" hardware.
The following explains some theory and pictures of my particular "build"
I dispensed with the LCD "contrast" pot' (less than full contrast makes and LCD difficult to see), but included a 200 ohm series "bright" control to reduce the brightness of the display.

I now wonder how I ever managed without such an instrument ?
Previously inductances were merely guess work (by looking at their physical size i.e. RF chokes etc, and capacitors were disgarded if the manufacturers markings had become obscured.)
Now you can easily measure, all kinds of recycled inductors and capacitors and grade/sort/label them, for future re-use.
I had a lot of bakelite encased silver-mica capacitors, which are highly regarded (long life, temp' stability, RF performance, voltage (surge) rating etc) but not of much use if you didn't know their value!





This is one of the most accurate and simplest LC inductance / capacitance Meters that one can find, yet one that you can easily build yourself.
This LC Meter allows to measure incredibly small inductances starting from 10nH to 1000nH,
1uH to 1000uH,
1mH to 100mH
and capacitance from 0.1pF up to 900nF.
LC Meter's circuit uses an auto ranging system so that way you do not need to spend time selecting ranges manually.
Another neat function is the "Zero Out" switch that will reset the initial inductance / capacitance, making sure that the final readings of the LC Meter are as accurate as possible.
Now let's use the above theory and apply it to electronics.
The LC Meter uses a popular LM311 IC that that functions as a frequency generator and this is exactly what we need.
If we want to calculate the value of an unknown inductor we use a known Ccal 1000pF capacitor and the value of an unknown inductor.
LM311 will generate a frequency that we can measure with a frequency meter.
Once we have this information we can use the frequency formula to calculate the inductance.
The same thing can be done for calculating the value of a unknown capacitor.
This time we don't know the value a capacitor so instead we use the value of a known inductor to calculate the frequency. Once we have that information we apply the formula to determine the capacitance.
All this sounds great, however if we want to determine the value of a lot of inductors / capacitors then this may become a very time consuming process.
Sure, we can write a computer program to do all these calculations, but what if we don't have an access to a computer or a frequency meter?
That's were PIC16F84A microchip comes handy.
PIC16F84A is like a small computer that can execute HEX programs that are written using an assembly language.
PIC16F84A is a very flexible microchip because it has PINs which can be configured as inputs and outputs.
Besides that, PIC16F84A IC requires very minimal number of external components like 4MHz crystal / resonator and few resistors depending on what project we are building.
Before we can use PIC16F84A microchip we have to program it with a HEX code which has to be sent from the computer.
In the next step we use the frequency generated by LM311 IC and pass it on to PIC16F84A's PIN 17. We designate this PIN as an input, as well as all other PINs that are directly connected to switches and jumpers.
User can use these inputs to tell the microchip to execute specified set of instructions or perform calculations.
Once the microchip will calculate the unknown inductance or capacitance it will use PINs that are designated as outputs and pass the results on to the 16 character LCD display.

LC Meter's Technical Specifications:

Voltage Supply: 7.5 - 15V
Accuracy: 1%
Zero Out Switch
Automatic Ranging

LC Meter's Inductance Measurement Ranges:
- 10nH - 1000nH
- 1uH - 1000uH
- 1mH - 100mH

LC Meter's Capacitance Measurement Ranges:
- 0.1pF - 1000pF
- 1nF - 900nF

LC Meter's Switches & Jumpers

SW1 - Zero out the readings.
SW2 - Capacitance / Inductance switch.
J1 - used by 16x2 two line character LCD displays.
J2 - displays the initial frequency of the LM311 oscillator which should be around 550KHz.

Most of the character LCD displays have 14 or 16 PINs.
The displays that do have a backlight have 16 PINs and displays that do not have a backlight have 14 PINs.
The PINs that are highlighted in green in the table below are the ones that PIC16F84A uses to pass the output information represented in bits (0/1).



PIN
Symbol
Function
States
1
VSS
GND
-
2
VDD
VCC +5V
+
3
VO
Contrast Adjustment
+/-
4
RS
Register Select
H/L
5
R/W
Read / Write
H/L
6
E
Enable Signal
H/L
7
DB0
Data Bit 0
H/L
8
DB1
Data Bit 1
H/L
9
DB2
Data Bit 2
H/L
10
DB3
Data Bit 3
H/L
11
DB4
Data Bit 4
H/L
12
DB5
Data Bit 5
H/L
13
DB6
Data Bit 6
H/L
14
DB7
Data Bit 7
H/L
15
LED Backlight VCC +5V
+
16
LED Backlight GND
-


The theory behind the measurementsThis section will involve maths and theory.
The LC – meter is actually an LC oscillator based around the familiar comparator circuit LM 311.
We are now dealing with an LC oscillator. The oscillating part is a parallel LC tank.
We will use the well known parallel resonance formula (see formula 1. below).

The formula say that if you connect an inductor parallel with a capacitor, it will have a resonance frequency (f).
L is the inductance in the resonance circuit.
C is the total capacitance in the resonance circuit.

If we connect an unknown capacitor called Cx parallel to C, we will get a lower resonance frequency (f2), due to the increased capacitance.
The formula would then look like this:

As you see, we have a new resonance frequency (f2) and you can see how Cx has been added to C.

Now divide f1 with f2. (formula 3.)

The inductance (L) in the formula has disappeared!
We now have a relationship between capacitances and frequency. (formula 4.)

So what does formula 4 show anyway?
Well, if we know the value of C, and we can measure f1 and f2, we will be able to use formula 4 to calculate Cx.

C is equal to all the parallel capacitance in the LC tank, but we do not know the C of the construction do we?
No we do not, but by making a calibration with a well known Cx, we can go backward and calculate C.
Before any measurement can be done, the LC meter need to perform a calibration to find out the constant value of C.
To find C, we use the formula 4 and break out C. (formula 5.)

The procedure start to measure f1 when only C exist.
Then we add a well known capacitor Cx (reference capacitor) to the LC unit and measure the frequency again (f2).

Since we know Cx (reference capacitor) and we have measured both f1 and f2, the micro controller will be able to calculate the constant value of C.

The procedure above is called the calibration phase.
In reality it is very easy, all you need to do is to press a button called calibrate and the micro controller handles it all for you!

What is important is that you use a very good capacitor for the calibration, else you will add error to measurement.
In my construction I use 1 nF 0.5%. The calibration capacitor will be added automatically with a relay. (more info later)

Now, when the micro controller knows the constant value of C, you can use formula 4 to measure any unknown capacitor at Cx.

Practical example:
To make this even more understandable, I will make a small calculation example to verify the calibration formula:

When I have no capacitor (Cx) connected to my LC-oscillator, I measure 610331Hz.
I connect a well known capacitor (Cx) of 1 nF 0.5% to the LC-oscillator and now the frequency drop to 508609 Hz.

Let’s use the calibration formula 5, above to calculate the value of C in the LC unit.
f1 = 610331, f2 = 508609 Hz, Cx = 440pF. The formula gives C to be 1 nF.
(remember that C is constant and equal to all the parallel capacitance in the LC tank)

Now, when I know C, let’s check if our calculation is correct.
In my measuring example I had an inductor of 68uH in the LC-oscillator.
I use the parallel resonance formula 1 :
When no Cx capacitor is connected I have L= 68uH and C=1000 pF, this gives resonance frequency = 610 331 Hz
When Cx capacitor is connected I have L= 68uH and C=1000 pF + Cx = 440pF, this gives resonance frequency = 508609 Hz
If we compare the calculated frequencies with the measured we can see that the calculation of C = 1000pF was correct. Great!

Now when we know the value of C, we can use formula 4, to measure any unknown value of Cx.

Lets look at the theory how to measure inductance.
We will still use the parallel resonance formula (formula 1,) but in this case we will add an unknown inductance Lx in serial with the L1.

We will have two states.
One when we only have the main inductor L1 connected with C, and a second state when we have the extra inductor Lx in serial with L1.
As you understand we will get two different resonance frequencies.

First state is when I only have L1 connected to C, and the frequency f1 will be produced from the LC-oscillator.
Formula 6 show you how I break out L1 from the parallel resonance formula. Only L1 exist. (Lx = 0)

Second state is when I add Lx in serial with L1 to form L2. Since the inductance increase the frequency (f2) will be produced from the LC-oscillator.
Formula 7 show you how I break out L2 from the parallel resonance formula. L1 and Lx are connected in serial to form L2

What we search for is Lx. (formula 8.). I put formula 6 and 7 into formula 8 and get formula 9.
After cleaning up we get formula 10. Let's look at this formula in more details. As you can see the main inductor L1 is gone.

To measure Lx, we only need to know the C, f1 and f2 of the LC-oscillator.
  • C will be calculated in the calibration phase (as I described earlier). 
  • f1 will be measured when the input is short circuited. 
  • f2 will be measured when Lx is connected to the input.

    Conclusion:
    It is possible to measure both capacitance and inductance as long as you have an accurate reference capacitor Cx for calibration of your measuring LC-meter.
    When it is calibrated you can connect either an unknown capacitor or inductor and measure its value. In this construction I have implemented the calibration so you only need to push a button. The microcontroller will then do all the work for you.
    Once again I have plaigarized heavily in order to produce this article.
    So credit must go to the following

    Ref 1. Electronics - DIY in New York
    Ref 2. "RF candy" in Sweden 
    Ref 3. Capacitance measurement using soundcard of a PC (in German language)
    Ref 4. Inductance measurement using soundcard of a PC (in German language)

    Addendum Jan 2013
    If you can't see youself fabricating an example; as per above, then;
    the Chinese are producing good cheap examples of L-C-F meters.
    This is typical of many cheap listings found on Ebay: (click to enlarge)
  • sai số của tụ

    C: +/- 0.25pF 
    D: +/- 0.5pF 
    F: +/- 1% 
    M: +/- 2% 
    J: +/- 5% 
    K: +/- 10% 
    M: +/- 20% 
    Z: -20% +80%