โอเช..ไปที่นี่เลย http://bit.ly/796EaX
Showing posts with label Microcontroller. Show all posts
Showing posts with label Microcontroller. Show all posts
Friday, January 22, 2010
โหลดหนังสือฟรี
โอเช..ไปที่นี่เลย http://bit.ly/796EaX
Labels:
Computer,
Microcontroller,
เรื่องทั่วไป
Sunday, October 25, 2009
ชิ้นส่วนที่รออยู่
1. PIC16F883 SSOP28 ต้องสั่งจาก farnell หรือไม่ก็ Mouser
มีแค่นี้
Labels:
Microcontroller
Friday, November 14, 2008
วงจรจับเวลา 99 วินาที ใช้ Microcontroller
วงจรเป็นดังรูปข้างล่างนี้

ส่วนโปรแกรมที่เป็นภาษาซี เขียนด้วย MikroC ก็เป็นดังข้างล่างนี้ครับ
//PIC16F627A
//4MHz Internal OSC
// Two Digit Counter
// 13/11/2008
// Punkky@gmail.com
#define Digit1 PORTA.F0
#define Digit2 PORTA.F1
unsigned short tick;
unsigned short x1;
unsigned short x2;
void interrupt () //Interrupt จะถูกเรียกทุกครั้งที่ Timer1 เกิดการ Overflow นั่นคือจะถูกเรียกทุกวินาทีนั่นเอง
{
PIR1.TMR1IF = 0; // clears TMR1IF
TMR1H = 0x80; //ตั้งค่าเริ่มต้นของ Timer1 เป็น 0x8000 โดยตั้งเฉพาะสองบิตแรก
tick = 1; //tick เป็น 1 ทุก 1 วินาที
}
void main(){
CMCON = 0x07; //Digital I/O for PORTA
TRISA = 0x00;
PORTA = 0x00;
TRISB = 0x00;
PORTB = 0x00;
T1CON = 0x0F;
// Prescaler 1:1 external clock
PIE1.TMR1IE = 1; // enable interupt to start the clock
INTCON = 0xC0; // Set GIE, PEIE
TMR1L = 0x00;
TMR1H = 0x80;
PCON.OSCF = 1; //Internal Clock 4MHz
x1 = 0; //หลักสิบของวินาที
x2 = 0; //หลักหน่วยของวินาที
tick = 0;
while(1){
if(tick){ //เมื่อเวลาผ่านไป 1 วินาที ค่า tick จะเป็น 1
tick = 0;
x2++; //เพิ่มหลักหน่วยของวินาทีขึ้น 1
if(x2>9){ //ถ้าหลักหน่วยมากกว่า เก้า ก็ให้เซ็ตเป็น ศูนย์ และนับหลักสิบขึ้น 1
x2 =0;
x1++;
if(x1>9){ //ถ้าหลักสิบมากกว่า เก้า ก็ให้เซ็ตเป็น ศูนย์ เพื่อกลับไปนับจาก 00 ใหม่
x1 = 0;
}
PORTB = x1; //นำค่าของหลักสิบไปแสดงผล
Digit1 = 1; //สั่งให้ CD4543 นำข้อมูลจาก PORTB ไปแสดงบน 7-Segment
Digit1 = 0; //สั่งให้ CD4543 คงค่าของตัวเลขไว้ โดยไม่ต้องสนใจค่าของ PORTB อีก
}
PORTB = x2; //นำค่าของหลักหน่วยไปแสดงผล
Digit2 = 1; //สั่งให้ CD4543 นำข้อมูลจาก PORTB ไปแสดงบน 7-Segment
Digit2 = 0; //สั่งให้ CD4543 คงค่าของตัวเลขไว้ โดยไม่ต้องสนใจค่าของ PORTB อีก
}
}
}
จำลองการทำงานด้วย Proteus ได้ตามภาพข้างล่าง
Labels:
Microcontroller
Saturday, November 08, 2008
ทำนาฬิกา Digital เล่นๆ (นาฬิกาจริงๆ ไม่ใช่ Flash)
นาฬิกา Digital ทำเองได้ ยังไม่เสร็จ เอามาแปะไว้ก่อน :)
รูปหน้านาฬิกาที่จะทำก็ประมาณนี้
Labels:
Microcontroller,
นาฬิกา
Saturday, October 11, 2008
นาฬิกาทำเองหลายๆแบบ My Digital Clock Collection
อันนี้เรือนแรกที่เริ่มทำ
อันนี้เป็นนาฬิกาที่ใช้ฐานเวลาจากดาวเทียม GPS ความเที่ยงตรงสุดยอดระดับนาฬิกาอะตอมครับ ใช้จอ LCD แสดงผล ตัวนี้ผมกำลังจะ upgrade จอไปเป็นจอแบบ OLED ที่สวยกว่า ได้จอมาแล้วแต่ยังไม่มีเวลาทำครับ นาฬิกาจะแสดง เวลา วัน วันที่ และจำนวนดาวเทียมที่เห็นตอนนี้ จริงๆแล้วได้ข้อมูล ละติจูด และ ลองจิจูด มาด้วย น่าจะคำนวณ Moon Phase (ข้างขึ้นข้างแรม),พวกน้ำขึ้นนำลง และ equation of time ได้ เอาไว้ทำเป็นโปรเจ็คต่อๆไปครับ
อันนี้ใช้จอ HDSP-211x ของ HP เป็นจอ Vintage ตอนนี้แค่จอนี้ตัวใหม่ก็หลายพันบาทครับ แสดงผลสีเหลืองสวยดี ตัวเลขแสดงเวลาจะวิ่งผ่านหน้าจอทุก 5 วินาที จออันนี้ตอนแรกผมว่าจะเอามาทำนาฬิกาข้อมือ แต่ติดปัญหาเรื่องกินไฟมาก
อันนี้ล่าสุด เป็นจอแบบ Led Dot Matrix ขนาด 8x8 จุด ขนาดประมาณ 2x2cm ใช้แสดงเวลาโดยเวลาจะวิ่งผ่านหน้าจอไปช้าๆ ตอนนี้ผมเพิ่งสั่งอันใหม่ขนาดจิ๋วทำตัวเลขสูงประมาณ 3mm ไป น่าจะได้นาฬิกาที่เล็กดี
เวลาแสดงผลมันก็วิ่งแบบนี้แหละครับ
เทียบขนาดของ HDSP กับ Led Dot Matrix 8x8 และ Project I
ทีนี้มาดูความเที่ยงตรงของนาฬิกาพวกนี้กัน นาฬิกาที่ผมทำนี้ใช้ตัว Crystal (หรือว่า Quartz นั่นเอง) ในการกำเนิดความถี่ (ยกเว้นตัว GPS clock ที่รับความถี่จากดาวเทียมโดยตรง) ความเที่ยงตรงตาม specของมันอยู่ที่ บวกลบ 1.5 วินาทีต่อวัน เท่าที่ผมลองวัดดูก็อยู่ประมาณนั้นแหละ ตัว Crystal ที่ใช้เป็นของ CITIZEN ครับ หน้าตาแบบนี้แหละ
แกะนาฬิกาข้อมือ(Quartz)ออกดูก็จะเห็นตัวประมาณนี้อยู่ในเครื่องนาฬิกา ซึ่งความเที่ยงตรงระดับนี้ผมยังไม่พอใจเพราะมันยังผิดเป็นนาทีถ้าวางทิ้งไว้เป็นปี ลองหาๆดูก็เจอ Crystal ที่มันเที่ยงตรงมากแบบผิดไปประมาณไม่กี่วินาทีในหนึ่งปี แต่ราคามันก็เอาเรื่อง (ตัวนึงเป็นหมื่น) ผมคงไม่เอามาลองหรอกครับมันแพงเกิน
นาฬิกาพวกนี้ผมทำแบบมือสมัครเล่น ดังนั้นท่านที่เป็นมืออาชีพด้านอิเล็กทรอนิสค์โดยตรงก็กรุณาชี้แนะด้วยครับ
ขอบคุณที่เข้ามาอ่านครับ
Labels:
Microcontroller,
นาฬิกา
Saturday, October 04, 2008
5x7 Led Dot Matrix ใช้ Microcontroller ตัวเดียว
สำหรับนาฬิกานี้ใช้ปุ่มสองปุ่มในการตั้งเวลา ถ้าใครสนใจอยากทำก็ส่ง comment ด้วยครับ จะได้เอารายละเอียดวิธีทำมาลงในนี้
Labels:
Microcontroller,
นาฬิกา
Saturday, September 06, 2008
Microcontroller
Labels:
Microcontroller
Tuesday, June 03, 2008
WDT: Watchdog Timer
But, there are some questions. Why my clock stopped? Will it happend again? How to overcome the problem?. After google around, I think I found a potential answers to the questions. I was thinking that microcontrollers are just electronics devices that will work as they promise as long as you provide power to them. But, I was wrong. PIC Microcontrollers can Hang Up or Freeze just like your computers. So, my clock can Freeze just like my PC :) .
Will it happend again?
Yes, it will happend again but nobody knows when.
How to overcome the problem?
Now, the hero is WDT or Watchdog Timer. It just like a dog who keeps comming to see the PIC every certain period of time. If the PIC can kick the dog (by clearing WDT register with CLRWDT command), the dog will go back and will come to see the PIC again next time. But if the PIC cannot kick the dog (the PIC is engaging infinity loop or just freezing), the dog will reset the PIC. One nice thing is that you don't have to wait until the dog comes before you can can kick it. You can kick the dog anytime you want but you have to make sure that you kick it before it resets the PIC. By using WDT, I think I can make my clock running helthly without human reset when it hang up.
How to use WDT?
I am no expert on PIC. So, I will show what I did and explain what I understand.
- Set CONFIG word to enable WDT
- In the code I set up 2 functions: FeedDog() and KickDog()
- Placing FeedDog() and KickDog() in the main program
I use mikroC compiler, so I uncheck the default WDT_OFF = $3FFB and check _WDT_ON = $3FFF
void FeedDog(){ //Setting WDT
OPTION_REG = 0x0F; //0b00001111 = Prescalar 1:128 .. reset every 2.3 sec. please consult data sheet for other presacalars
asm{CLRWDT} //Clear WDT
}
void KickDog(){
asm{ CLRWDT } //Clear WDT before the dog resets the PIC
}
I put FeedDog() around the begining of the program to set up WDT and put KickDog() wherever I think the dog will come. If the program is very long, I can put KickDog() in many places as I want if I think the dog will come after that line of code. It is upto me to calculate where to put the KickDog(). In my case, the dog keeps comming every 2.3 sec so I have to kick the dog before 2.3 sec after each kick. My clock update every second, so if it freeze and cannot kick the dog in 2.3 sec the PIC will be reset.
Putting KickDog() in the wrong place can make your program running incorrectly. Please be careful.
void main(){
.. Set up program ..
FeedDog();
.. Set up some more things..
while(1){
...
.. Do tasks ..
KickDog();
...Do tasks..
....
}
}
To be revised with images and more details
Labels:
Microcontroller
Subscribe to:
Posts (Atom)