1. Trang chủ
  2. » Giáo án - Bài giảng

Thực hành vi điều khiển

44 0 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Thực Hành Vi Điều Khiển
Trường học Hutech University
Chuyên ngành Electronics
Thể loại Graduation Project
Năm xuất bản 2021
Thành phố Ho Chi Minh City
Định dạng
Số trang 44
Dung lượng 718,27 KB

Cấu trúc

  • 1.1 LED (0)
  • 1.2 LED 7 (14)
  • 1.3 CÔNG (20)
  • 1.4 LCD (23)
  • BÀI 2: (29)
    • 2.1 TIMER (29)
    • 2.2 TIMER (0)
  • BÀI 3: ADC VÀ PWM (35)
    • 3.1 ADC (36)
    • 3.2 PWM (40)

Nội dung

t chu kì duty cho PWM2.

LED 7

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#use delay(clock=8M) void main (void)

{ output_d(0xFF); output_b(0x03); output_low(PIN_D3); while (1) ;

RC0 RC1 RC2 RC3 RC4 RC5 RC6 RC7

RC1/T1OSI/CCP2 16 RC2/CCP1 17 RC3/SCK/SCL 18

RB7/PGD 40 RB6/PGC RB5 RB4 39 38 37 RB3/PGM RB0/INT RB2 RB1 36 35 34 33

RD7/PSP7 30 RD6/PSP6 29 RD5/PSP5 28 RD4/PSP4 27 RD3/PSP3 22 RD2/PSP2 21

RC7/RX/DT 26 RC6/TX/CK RC5/SDO 25 24 RC4/SDI/SDA 23

CÔNG

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#define SW2 PIN_B5 void main (void)

{ if(!input(SW1)) output_high(D5); if(!input(SW2)) output_low(D5);

RC0 RC1 RC2 RC3 RC4 RC5 RC6 RC7

RD0 RD1 RD2 RD3 RD4 RD5 RD6 RD7

RC1/T1OSI/CCP2 16 RC2/CCP1 17 RC3/SCK/SCL 18

RB7/PGD 40 RB6/PGC RB5 RB4 39 38 37 RB3/PGM RB0/INT RB2 RB1 36 35 34 33

RD7/PSP7 30 RD6/PSP6 29 RD5/PSP5 28 RD4/PSP4 27 RD3/PSP3 22 RD2/PSP2 21

RC7/RX/DT RC6/TX/CK RC5/SDO 26 25 24 RC4/SDI/SDA 23

LCD

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#include void main (void)

{ lcd_init(); lcd_gotoxy(1,1); printf(lcd_putc,"Welcome to"); delay_ms(3); lcd_gotoxy(1,2); printf(lcd_putc,"*****HUTECH*****"); delay_ms(3); while(1) ;

RC1/T1OSI/CCP2 16 RC2/CCP1 17 RC3/SCK/SCL 18

RB7/PGD 40 RB6/PGC RB5 RB4 39 38 37 RB3/PGM RB0/INT RB2 RB1 36 35 34 33

RD7/PSP7 30 RD6/PSP6 29 RD5/PSP5 28 RD4/PSP4 27 RD3/PSP3 22 RD2/PSP2 21

RC7/RX/DT RC6/TX/CK RC5/SDO 26 25 24 RC4/SDI/SDA 23

TIMER

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#use delay(clock=8M) void delay400ms()

Setup_timer_1(T1_INTERNAL|T1_DIV_BY_2)

Bài 2.2: setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

Output_b(0xe3); output_low(PIN_D

{ enable_interrupts(GLOBAL); enable_interrupts(INT_TIMER1); setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); while(1);

Setup_timer_0(RTCC_DIV_64|RTCC_INTERNAL)

Setup_timer_1(T1_INTERNAL| T1_DIV_BY_1)

TIMER

2 Setup_adc(ADC_CLOCK_INTERNAL)

3 Setup_adc_ports(value) value:

AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF // Vref = VRA3

AN0_AN1_AN2_AN3_AN4 // Vref = VDD

AN0_AN1_AN2_AN4_VSS_VREF // Vref = VRA3

AN0_AN1_AN3 // Vref = VDD

AN0_AN1_VSS_VREF // Vref = VRA3

AN0_VREF_VREF // A0; +Vref = VRA3, -Vref = VRA2

2 setup_ccp t CCP2 là PWM

3 setup_timer_2(T2_DIV_BY_4, 100,1); //f = ~2.5 KHz, XTAL = 4MHZ

4 t chu kì duty cho PWM1

5 t chu kì duty cho PWM2

ADC VÀ PWM

ADC

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#use delay(clock=8M) int8 LED7S[10] = {0x03, 0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09}; int8 LED7S1[10] = {0x02,

0x9e,0x24,0x0c,0x98,0x48,0x40,0x1e,0x00,0x08}; int8 data_led[4] = {0xFF,0xFF,0xFF,0xFF}; int8 control_led[4] = {0xF7,0xFB,0xFD,0xFE}; int8 tram,chuc,dvi; int16 temp; float volt;

RC1/T1OSI/CCP2 16 RC2/CCP1 17 RC3/SCK/SCL 18

RB7/PGD 40 RB6/PGC RB5 RB4 39 38 37 RB3/PGM RB0/INT RB2 RB1 36 35 34 33

RD7/PSP7 30 RD6/PSP6 29 RD5/PSP5 28 RD4/PSP4 27 RD3/PSP3 22 RD2/PSP2 21

RC7/RX/DT 26 RC6/TX/CK RC5/SDO 25 24 RC4/SDI/SDA 23

SW2 output_d(0xFF); output_b(data_led[i]); output_d(control_led[i]); delay_ms(2);

{ enable_interrupts(GLOBAL); enable_interrupts(INT_TIMER0);

Setup_timer_0(RTCC_DIV_128|RTCC_INTERNAL);

// Cau hinh ADC setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0); set_adc_channel(0); while (1)

{ temp = read_adc(); volt = (float)(temp)*5/10.23; temp = (int16)volt; chuc = temp/10; dvi = temp%10; data_led[0] = LED7S[chuc]; data_led[1] = LED7S[dvi]; data_led[2] = 0x39; data_led[3] = 0x63;

PWM

#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP

#use delay(clock=8M) void main (void)

Setup_timer_2(T2_DIV_BY_1,99,1); setup_ccp1(CCP_PWM); setup_ccp2(CCP_PWM); set_pwm1_duty(30); set_pwm2_duty(90); while (1) ;

RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB7

RB6 RB5 RB4 RB3 RB2 RB1

RC1/T1OSI/CCP2 16 RC2/CCP1 17 RC3/SCK/SCL 18

RB7/PGD 40 RB6/PGC RB5 RB4 39 38 37 RB3/PGM RB0/INT RB2 RB1 36 35 34 33

RD7/PSP7 30 RD6/PSP6 29 RD5/PSP5 28 RD4/PSP4 27 RD3/PSP3 22 RD2/PSP2 21

RC7/RX/DT 26 RC6/TX/CK RC5/SDO 25 24 RC4/SDI/SDA 23

Bài 3.5: bài 3.4 quay cho MG1 (dùng

Ngày đăng: 06/02/2024, 10:02

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w