0% found this document useful (0 votes)
16 views7 pages

GGGG

Uploaded by

levanphuongcdt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

GGGG

Uploaded by

levanphuongcdt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <TIMER_1_3LEDSEG_ROI.h> #include <ADC.

h>
unsigned char MA7DOAN[] UNSIGNED INT16 KQADC;
={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0x UNSIGNED J,MATRAN;
F8,0x80,0x90}; CONST UNSIGNED CHAR
unsigned int16 t1; MA7DOAN[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,
unsigned char madonvi,machuc,matram; 0XF8,0X80,0X90};
void giaima() { VOID HIEN_THI()
matram=ma7doan[t1/100]; {
machuc=ma7doan[t1/10%10]; MATRAN=MA7DOAN[KQADC/100];
madonvi=ma7doan[t1%10]; IF(MATRAN==0XC0)
if(matram==0xc0) MATRAN=0XFF;
{ OUTPUT_B(MA7DOAN[KQADC%10]);
matram=0xff; OUTPUT_C(MA7DOAN[KQADC/10%10]);
if(machuc==0xc0) OUTPUT_D(MATRAN);
{ }
machuc=0xff; VOID MAIN()
}}} {
void hienthi() SET_TRIS_B(0X00);
{ SET_TRIS_C(0X00);
output_b(madonvi); SET_TRIS_D(0X00);
output_low(pin_d0); SET_TRIS_A(0XFF);
delay_ms(1); output_high(pin_d0); SETUP_ADC(ADC_CLOCK_DIV_2);
output_b(machuc); SETUP_ADC_PORTS(AN0);
output_low(pin_d1); SET_ADC_CHANNEL(0);
delay_ms(1); output_high(pin_d1); WHILE(TRUE)
output_b(matram); {
output_low(pin_d2); KQADC=0;
delay_ms(1); output_high(pin_d2); FOR (J=0;J<200;J++)
} {
void main() KQADC=KQADC+READ_ADC();
{ DELAY_MS(1);
set_tris_b(0x00); set_tris_d(0x00); }
KQADC=KQADC/2.046;
setup_timer_1(t1_external|t1_div_by_1); KQADC=KQADC/200;
set_timer1(0); HIEN_THI();
while(true) }}
{
t1=get_timer1();
giaima();
hienthi();
}
}
#include <ADC2.h> // 3ledSEG noi tiep
UNSIGNED INT16 KQADC;
UNSIGNED INT J, MADONVI, MACHUC,
MATRAM;
unsigned char MA7DOAN[10]
={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0x
F8,0x80,0x90}; // ma led
void giaima()
{
MATRAM=MA7DOAN[KQADC/100];
MACHUC=MA7DOAN[KQADC/10%10];
MADONVI=MA7DOAN[KQADC%10];
IF(MATRAM==0XC0) MATRAM=0XFF;
}
void hienthi()
{ OUTPUT_B(MADONVI);
OUTPUT_LOW(PIN_D0);
DELAY_MS(1);
OUTPUT_HIGH(PIN_D0);
OUTPUT_B(MACHUC);
OUTPUT_LOW(PIN_D1);
DELAY_MS(1);
OUTPUT_HIGH(PIN_D1);
OUTPUT_B(MATRAM);
OUTPUT_LOW(PIN_D2);
DELAY_MS(1);
OUTPUT_HIGH(PIN_D2);
}
void main()
{
SET_TRIS_B(0X00);
SET_TRIS_D(0X00);
SET_TRIS_A(0X01);
SETUP_ADC(ADC_CLOCK_DIV_2);
SETUP_ADC_PORTS(AN0);
SET_ADC_CHANNEL(0);
while(TRUE)
{
KQADC=0;
FOR(J=0;J<100;J++)
{
KQADC=KQADC+READ_ADC();
HIENTHI();
}
KQADC=KQADC/2.046;
KQADC=KQADC/100;
GIAIMA();
}}
#include <dk_dongco.h> // dk dong co if(!input(start))
#define dc pin_a0 {
#define up pin_a3 if(capdo<1)
#define dw pin_a4 {
#define stop pin_a5 capdo++;
#define start pin_a1 set_pwm1_duty(capdo*100);
signed int capdo=0; do{} while(!input(start));
void phim_up() // tang toc }}}}
{
if(!input(up)) // kiem tra nut nhan co nhan hay void phim_dc() // dao chieu
khong {
{ IF(INPUT(PIN_A0)==0)
delay_ms(20); // delay 20ms kt nut co nhan {
hay khong while(!input(pin_a0));
if(!input(up)) OUTPUT_toggle(Pin_b0); // DAO TRANG THAI
{ PIN_B0
if(capdo<10) OUTPUT_toggle(Pin_b1); // DAO TRANG THAI
{ PIN_B1
capdo++; set_pwm1_duty(capdo*100); }
//capdo*10 la moi lan nhan tang cap do len 10 }
do {} while(!input(up)); // chong doi void main()
phim {
}}}} set_tris_c(0x00);
void phim_dw() // giam toc set_tris_b(0x00);
{ set_tris_e(0x00);
if(!input(dw)) setup_ccp1(ccp_pwm); //
{ setup_timer_2(t2_div_by_4,249,1); // BO CHIA
delay_ms(20); TRUOC LA 4, BO CHIA SAU LA 1,PR2 = 249
if(!input(dw)) set_pwm1_duty(capdo*100);
{ OUTPUT_high(Pin_b0);
if(capdo>0) OUTPUT_low(pin_b1);
{ while(TRUE)
capdo--; {
set_pwm1_duty(capdo*100); phim_up();
do {} while(!input(dw)); phim_dw();
}}}} phim_stop();
void phim_stop() // dung dc phim_dc();
{ }}
if(!input(stop))
{
capdo=0;
set_pwm1_duty(capdo*100);
}}
void phim_start() // bat dau
{
if(!input(start))
{ delay_ms(20);
#include <ngat_dk_dc_trenLCD.h> if(capdo>0)
#BIT TMR1IF =0X0C.0 {
UNSIGNED INT16 DEMXUNG2=0; capdo--;
set_pwm1_duty(capdo*10);
#define LCD_ENABLE_PIN PIN_D1 do {} while(!input(DOWN));
#define LCD_RS_PIN PIN_D2 }}}}
#define LCD_RW_PIN PIN_D3 void up()
#define LCD_DATA4 PIN_D4 {
#define LCD_DATA5 PIN_D5 if(!input(up)) // kiem tra nut nhan co nhan hay khong
#define LCD_DATA6 PIN_D6 {
#define LCD_DATA7 PIN_D7 delay_ms(20); // delay 20ms kt nut co nhan hay khong
#INCLUDE <LCD.C> // khai bao thu vien lcd.c if(!input(up))
{
#define START pin_RB4 if(capdo<10)
#define stop pin_RB5 {
#define up pin_RB6 capdo++; set_pwm1_duty(capdo*10); // capdo*10 la moi lan
#define down pin_RB7 nhan tang cap do len 10 lan
signed int capdo=0; do {} while(!input(up)); // chong doi phim
}}}}
#INT_RB void LCD()
void START() {
{ lcd_init();
if(!input(START)) setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_1);
{ delay_ms(20); while(TRUE)
if(!input(START)) {
{ set_RTCC(0);
if(capdo<1) DELAY_MS(1000);
{ UNSIGNED INT16 a=get_rtcc();
capdo++; lcd_gotoxy(1,1);
set_pwm1_duty(capdo*10); printf(lcd_putc,"XUNG/S:%lu",a);
do{} while(!input(START)); UNSIGNED INT16 b = (a*60)/50;
}}} lcd_gotoxy(1,2);
void stop() printf(lcd_putc,"VONG/ph:%lu",a);
{ }}}
if(!input(stop)) void main()
{ {
capdo=0; set_tris_c(0x00);
set_pwm1_duty(capdo*100); set_tris_b(0x00);
} } set_tris_e(0x00);
setup_ccp1(ccp_pwm); //
void DOWN() setup_timer_2(t2_div_by_4,124,1); // BO CHIA TRUOC LA 4, BO
{ CHIA SAU LA 1,PR2 = 249
if(!input(DOWN)) set_pwm1_duty(capdo*10);
{
delay_ms(20);
if(!input(DOWN))
{
if(capdo>0)
{
capdo--;
set_pwm1_duty(capdo*10);
do {} while(!input(DOWN));
}}}}
void up()
{
if(!input(up)) // kiem tra nut nhan co nhan hay khong
{
delay_ms(20); // delay 20ms kt nut co nhan hay khong
if(!input(up))
{
if(capdo<10)
{
capdo++; set_pwm1_duty(capdo*10); // capdo*10 la moi
lan nhan tang cap do len 10 lan
do {} while(!input(up)); // chong doi phim
}}}}
void LCD()
{
lcd_init();
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_1);
while(TRUE)
{
set_RTCC(0);
DELAY_MS(1000);
UNSIGNED INT16 a=get_rtcc();
lcd_gotoxy(1,1);
printf(lcd_putc,"XUNG/S:%lu",a);
UNSIGNED INT16 b = (a*60)/50;
lcd_gotoxy(1,2);
printf(lcd_putc,"VONG/ph:%lu",a);
}}}
void main()
{
set_tris_c(0x00);
set_tris_b(0x00);
set_tris_e(0x00);
setup_ccp1(ccp_pwm); //
setup_timer_2(t2_div_by_4,124,1); // BO CHIA TRUOC LA 4, BO
CHIA SAU LA 1,PR2 = 249
set_pwm1_duty(capdo*10);
OUTPUT_high(Pin_b0);
OUTPUT_low(pin_rb0);
while(TRUE)
{
START();
DOWN();
stop();
up();
LCD();
}}

You might also like