Tuesday, April 2, 2013

Điều chỉnh độ sáng tối bóng đèn bằng remote tivi Sony dùng vi điều khiển pic12f683

Posted by dientudieukhien at 4:10 PM 0 Comments
Sơ đồ nguyên lý:

Code viết bằng ngôn ngữ Mikroc:

The code devided into 2 parts, AC chopper for light dimming control and SIRC decoding for input remote control. As I mention earlier, the SIRC decoding part is on my previous example. For dimming control, GP3 is setup as interrupt-on-change, that's mean INTCON.GPIF is set every zero-crossing is dectected, then microcontroller performs delay by using the Timer1 then activates the triac.

#define tx GPIO.GP5

unsigned TMR1 absolute 0x0E;

char current_dim = 0;
char done_flag = 0;
//preload timer1 value 100%, 90%, 80%, 70% 60%, 50%, 40%, 30% 20% and 10%
unsigned preload_time[10] = {65535,63823,63082,62481,61925,61370,60814,\
60259,59656,58916};

//************************************************** ****************************
//*** interrupt-on-change when zero-crossing occur, preload timer1 value
//*** turn on timer1 to perform delay before gate trigger
//************************************************** ****************************
if(INTCON.GPIF){
tx = 1;
TMR1 = preload_time[current_dim];//preload_time into Timer1
T1CON.TMR1ON = 1; //start timer1
INTCON.GPIF = 0;
}
//************************************************** ****************************
//*** perform gate trigger, turn off itself
//************************************************** ****************************
if(PIR1.TMR1IF){
T1CON.TMR1ON = 0; //stop timer1
tx = 0; //turn on triac
delay_us(150);
tx = 1; //turn off triac
PIR1.TMR1IF = 0; //clear interrupt flag
}
}
At 60 Hz AC power line, one circle is 16.6667 milliseconds, half circle is 8.333 milliseconds. If the microcontroller delay 4166 us before activate the triac on both side, positive and negative, then the light bulb would have half of the power. In this project, the 8.333ms is divided into 10 steps for the power control by calculation then put it into preload_time variable. The program decode SIRC VOL+ key for step up and VOL- key for step down(dim) by changeing current_dim variable.

if(done_flag == 0){
if(got_data){
Command_code = input_data & 0x7F;
Device_code = input_data >> 7;
if(Device_code == 1){
switch (Command_code){
case 0x12: if(current_dim > 0) current_dim --;
break;
case 0x13: if(current_dim < 9) current_dim ++;
break;
}
}
done_flag = 1;
}
}



Nguồn: http://www.pic_examples.byethost3.com/

Click vào link tải ở trên đợi 5 giây, ấn "Bỏ qua quảng cáo". Click the link above, wait for 5s and click button "Skip Ad"

Chia sẽ bài viết này

Cập nhật tin bài mới

Subscribe địa chỉ mail để nhận tin nhanh chóng. Chúng tôi sẽ giữ bí mật địa chỉ mail của bạn.

0 nhận xét:

    tab

back to top