: Cấu tạo của Mosfet
4) Chương trìn h:
Thiết lập các module sử dụng cho bài này : Các pác phải thiết lập được drrive của Timer 16, counter 8, LCD (Có thể download chương trình về tham khảo cấu hình phần cứng)
* Chương trình hiện thị :
#include // part specific constants and macros
#include "PSoCAPỊh" // PSoC API definitions for all User Modules #include "lcd.h"
void LCD_1_Clear(unsigned char x,unsigned char y) {
char trong[]=" "; LCD_1_Position(x,y); LCD_1_PrString(trong); }
void lcd1digit(int data,unsigned char x,unsigned char y) {
LCD_1_Position(x,y);
LCD_1_WriteDatắ0'+data); LCD_1_Clear(x,y+1);
}
void lcd2digit(int data,unsigned char x,unsigned char y) {
LCD_1_Position(x,y);
LCD_1_WriteDatắ0'+data/10); data=data%10;
LCD_1_WriteDatắ0'+data); LCD_1_Clear(x,y+2);
}
void lcd3digit(int data,unsigned char x,unsigned char y) { LCD_1_Position(x,y); LCD_1_WriteDatắ0'+data/100); data=data%100; LCD_1_Position(x,y+1); LCD_1_WriteDatắ0'+data/10); data=data%10; LCD_1_Position(x,y+2); LCD_1_WriteDatắ0'+data); LCD_1_Clear(x,y+3); }
void lcd4digit(int data,unsigned char x,unsigned char y) { LCD_1_Position(x,y); LCD_1_WriteDatắ0'+data/1000); data=data%1000; LCD_1_Position(x,y+1); LCD_1_WriteDatắ0'+data/100); data=data%100; LCD_1_Position(x,y+2); LCD_1_WriteDatắ0'+data/10); data=data%10; LCD_1_Position(x,y+3); LCD_1_WriteDatắ0'+data); LCD_1_Clear(x,y+4); }
void lcd5digit(int data,unsigned char x,unsigned char y) { LCD_1_Position(x,y); LCD_1_WriteDatắ0'+data/10000); data=data%10000; LCD_1_Position(x,y+1); LCD_1_WriteDatắ0'+data/1000); data=data%1000; LCD_1_Position(x,y+2); LCD_1_WriteDatắ0'+data/100); data=data%100; LCD_1_Position(x,y+3); LCD_1_WriteDatắ0'+data/10); data=data%10;
LCD_1_Position(x,y+4); LCD_1_WriteDatắ0'+data); LCD_1_Clear(x,y+5);
}
void lcd_hienthi(int data,unsigned char x,unsigned char y) {
if(data<10) lcd1digit(data,x,y); else if(data<100) lcd2digit(data,x,y); else if(data<1000) lcd3digit(data,x,y); else if(data<10000) lcd4digit(data,x,y); else lcd5digit(data,x,y);
}
* Chương trình chính :
/--- // C main line
// Do toc do dong co v/s-- Cap cho dong co DC12V // Viet boi : biendt - biendt.biendt@gmail.com
//website : http://biendt.biz // Encoder : P0_2
// Timer : 0.01s //
//--- #include // part specific constants and macros
#include "PSoCAPỊh" // PSoC API definitions for all User Modules #include "LCD.h"
#define max 255
unsigned char count,oldcount,newcount=0; unsigned char dem=0;
unsigned char vt=0; void khoitaoht() {
LCD_1_Start();
Timer16_1_WritePeriod(9); //dat thoi gian la 0.01s Timer16_1_WriteCompareValue(0);
Timer16_1_EnableInt(); Timer16_1_Start();
Counter8_1_WritePeriod(max); // thiet lap dem! Counter8_1_WriteCompareValue(0);
Counter8_1_EnableInt(); Counter8_1_Start();
}
#pragma interrupt_handler Timer16_1_ISR void Timer16_1_ISR(void)
{
dem++; // kiem tra xem nao ngat co hoat dong khong oldcount=newcount; newcount=max-Counter8_1_bReadCounter(); if(newcount count=max-(oldcount-newcount); else count=newcount-oldcount; vt=count; // vong/s } void main() { M8C_EnableGInt; khoitaoht(); LCD_1_Position(0,0); LCD_1_PrCString("s/x:"); LCD_1_Position(1,0); LCD_1_PrCString("v/t:"); LCD_1_Position(1,8); LCD_1_PrCString("v/s"); while(1) {
lcd_hienthi(count,0,5); // hien thi xung dem lcd_hienthi(dem,0,9); // hien thi gia trri vao ngat lcd_hienthi(vt,1,5); // hien thi toc do cua dong co }