Untitled
unknown
abc
4 years ago
4.2 kB
5
Indexable
#include <Barcode_CCS.h> #use delay(clock = 4000000) //#use fast_io(D) #use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8) // khai bao thu vien LCD #define LCD_ENABLE_PIN PIN_C3 #define LCD_RS_PIN PIN_D1 #define LCD_RW_PIN PIN_D0 #define LCD_DATA4 PIN_D2 #define LCD_DATA5 PIN_D3 #define LCD_DATA6 PIN_C4 #define LCD_DATA7 PIN_C5 #include <lcd.c> // LED #define LED1 PIN_B1 #define LED2 PIN_B2 #define LED3 PIN_D4 // Cam Bien #define CB1 PIN_A0 #define CB2 PIN_A1 #define CB3 PIN_A2 // Dong co servo #define SERVO1 PIN_B4 #define SERVO2 PIN_B5 // Cac bien int demsp1=0, demsp2=0, demsp3=0;// bien dem so luong san pham // Kiem tra hoat dong mach void hdmach() { output_high(LED1); output_high(LED2); } // Chay bang tai - Dong co DC void chaybangtai() { output_low(PIN_C2); // cho phep dong co quay output_low(PIN_C0); // dong co quay thuan 1 chieu output_high(PIN_C1); set_pwm1_duty(500); } // nhan du lieu tu may tinh void nhandata() { output_high(LED3); char c = getch(); if (c=="0") // nhan start o VS chay bang tai { chaybangtai(); } if (c=="1") // nhan stop o VS dung bang tai { output_low(PIN_C0); output_low(PIN_C1); } if (c=="2") // cam bien tai 1 { demsp1++; output_high(SERVO1); // mo servo o 1 ra 90 do delay_us(1500); output_low(SERVO1); delay_us(18500); lcd_init(); // hien thi len LCD lcd_putc("\f"); delay_ms(200); lcd_gotoxy(1,1); lcd_putc(" SAN PHAM LOAI 1" ); lcd_gotoxy(1,2); printf(LCD_PUTC, "SO LUONG = %u",demsp1); } if (c=="3") // cam bien tai 2 { demsp2++; output_high(SERVO2); // mo servo o 2 ra 90 do delay_us(1500); output_low(SERVO2); delay_us(18500); lcd_init(); // hien thi len LCD lcd_putc("\f"); delay_ms(200); lcd_gotoxy(1,1); lcd_putc(" SAN PHAM LOAI 2" ); lcd_gotoxy(1,2); printf(LCD_PUTC, "SO LUONG = %u",demsp2); } if (c=="4") // o khung loi { demsp3++; lcd_init(); // hien thi len LCD lcd_putc("\f"); delay_ms(200); lcd_gotoxy(1,1); lcd_putc(" SAN PHAM LOI" ); lcd_gotoxy(1,2); printf(LCD_PUTC, "SO LUONG = %u",demsp3); } } void cambien() { if (input(CB1) == 0) { output_low(PIN_C0); output_low(PIN_C1); delay_ms(1000); output_high(PIN_C0); output_high(PIN_C1); } if (input(CB2) == 0) { delay_ms(500); output_high(SERVO1); // dong servo ve 0 do delay_us(1000); output_low(SERVO1); delay_us(19000); } if (input(CB3) == 0) { output_high(SERVO2); // dong servo ve 0 do delay_us(1000); output_low(SERVO2); delay_us(19000); } } void main() { setup_timer_2(T2_DIV_BY_4,250,1); // dung timer2 bo chia truoc 4, gia tri dinh 250, bo chia sau 1 // set_timer2(1); setup_ccp1(CCP_PWM); // bam xung dieu khien toc do dong co set_pwm1_duty(500); // tam thoi set up chay 50% set_tris_a(0x07); // set chan A0 A1 A2 la chan nhan tin hieu vao set_tris_b(0xcf); // set chan B4 B5 xuat tin hieu ra con lai nhan tin hieu vao set_tris_c(0x00); // set toan bo port C xuat tin hieu ra set_tris_d(0x00); // set toan bo port D xuat tin hieu ra set_tris_e(0x00); // set toan bo port E xuat tin hieu ra port_b_pullups(1); // kich hoat dien tro noi while(TRUE) { lcd_init(); // hien thi len LCD lcd_putc("\f"); delay_ms(200); lcd_gotoxy(1,1); lcd_putc(" DO AN VI DIEU KHIEN" ); lcd_gotoxy(1,2); lcd_putc(" PHAN LOAI SAN PHAM" ); hdmach(); nhandata(); cambien(); } }
Editor is loading...