บทความ

กำลังแสดงโพสต์จาก กุมภาพันธ์, 2019

mikro c 6

รูปภาพ
 ใบรายงานผลการปฏิบัติงาน Code PORTB = Hex(s%10); PORTD.F2 = 1; Delay_ms(10); PORTD.F2 = 0; PORTB = Hex((s/10)%10); PORTD.F1 = 1; Delay_ms(10); PORTD.F1 = 0; PORTB = Hex((s/100)%10); PORTD.F0 = 1; Delay_ms(10); PORTD.F0 = 0; unsigned int Hex(int a) { switch(a) { case 1: return 0x06; case 2: return 0x5B; case 3: return 0x4F; case 4: return 0x66; case 5: return 0x6D; case 6: return 0x7D; case 7: return 0x07; case 8: return 0x7F; case 9: return 0x6F; case 0: return 0x3F; } } ภาพจำลองการทำงานด้วยโปรแกรม Proteus อ้างอิง https://electrosome.com/matrix-keypad-pic-microcontroller/

mikro c5

รูปภาพ
   ใบรายงานผลการปฏิบัติงาน Code char readKeyboard() { unsigned int i = 0; for(i=0;i<4;i++) { if(i == 0) PORTB = 1; else if(i == 1) PORTB = 2; else if(i == 2) PORTB = 4; else if(i == 3) PORTB = 8; if(PORTB.F4) return findKey(i,0); if(PORTB.F5) return findKey(i,1); if(PORTB.F6) return findKey(i,2); if(PORTB.F7) return findKey(i,3); } return ' '; } char findKey(unsigned short a, unsigned short b) { if(b == 0) { if(a == 3) return '0'; else if(a == 2) return '1'; else if(a == 1) return '2'; else if(a == 0) return '3'; } else if(b == 1) { if(a == 3) return '4'; else if(a == 2) return '5'; else if(a == 1) return '6'; else if(a == 0) return '7'; } else if(b == 2) { if(a == 3) return '8'; else if(a == 2) return '9'; else if(a == 1) return 'A'; else if(a == 0) r...

mikro c 4

รูปภาพ
    ใบรายงานผลการปฏิบัติงาน Code sbit LCD_RS at RB4_bit ; sbit LCD_EN at RB5_bit ; sbit LCD_D4 at RB0_bit ; sbit LCD_D5 at RB1_bit ; sbit LCD_D6 at RB2_bit ; sbit LCD_D7 at RB3_bit ;   sbit LCD_RS_Direction at TRISB4_bit ; sbit LCD_EN_Direction at TRISB5_bit ; sbit LCD_D4_Direction at TRISB0_bit ; sbit LCD_D5_Direction at TRISB1_bit ; sbit LCD_D6_Direction at TRISB2_bit ; sbit LCD_D7_Direction at TRISB3_bit ; unsigned int adcvalue , value , temp_res ; unsigned char car , x , y ; char * voltage = "00.00" ; long temp ;   // Routine to show the value of the ADC_read void ShowADC ( int x , int y , unsigned int adcvalue ) { car = adcvalue / 1000 ; LCD_Chr ( x , y , 48 + car ) ; adcvalue = adcvalue - 1000 * car ; car = ( adcvalue / 100 ) ; LCD_Chr_CP ( 48 + car ) ; adcvalue = adcvalue - 100 * car ; car = ( adcvalue / 10 ) ; LCD_Chr_CP ( 48 + car ) ; adcvalue = adcvalue - 10 * car ; car = adcvalue ; LCD_Chr_CP ( 48 + c...

mikro c 3

รูปภาพ
                 ใบรายงานผลการปฏิบัติงาน Code unsigned int i; unsigned int duty_50; void main(){ ADPCFG = 0xFFFF; // initialize AN pins as digital PORTB = 0xAAAA; TRISB = 0; // initialize portb as output Delay_ms(1000); duty_50 = PWM1_MC_Init(5000, 0, 0x01, 0); // Pwm_Mc_Init returns 50% of the duty PWM1_MC_Set_Duty(i = duty_50, 1); PWM1_MC_Start(); do { i--; PWM1_MC_Set_Duty(i, 1); Delay_ms(10); if (i == 0) i = duty_50 * 2 - 1; // Let us not allow the overflow PORTB = i; } while(1); ภาพจำลองการทำงานด้วยโปรแกรม Proteus อ้างอิง http://download.mikroe.com/documents/compilers/mikroc/dspic/help/pwm_motor_library.htm

mikro c 2

รูปภาพ
    ใบรายงานผลการปฏิบัติงาน Code void main() { TRISB.F0 = 0; //Makes PORTB0 or RB0 Output Pin while(1) //Infinite Loop { PORTB.F0 = 1; //LED ON Delay_ms(1000); //1 Second Delay PORTB.F0 = 0; //LED OFF Delay_ms(1000); //1 Second Delay } } ภาพจำลองการทำงานด้วยโปรแกรม Proteus vอ้างอิง https://electrosome.com/led-blinking-pic/

mikro c 1

รูปภาพ
              ใบรายงานผลการปฏิบัติงาน Code // LCD module connections sbit LCD_RS at RC2_bit; sbit LCD_EN at RC3_bit; sbit LCD_D4 at RC4_bit; sbit LCD_D5 at RC5_bit; sbit LCD_D6 at RC6_bit; sbit LCD_D7 at RC7_bit; sbit LCD_RS_Direction at TRISC2_bit; sbit LCD_EN_Direction at TRISC3_bit; sbit LCD_D4_Direction at TRISC4_bit; sbit LCD_D5_Direction at TRISC5_bit; sbit LCD_D6_Direction at TRISC6_bit; sbit LCD_D7_Direction at TRISC7_bit; // End LCD module connections void main() { Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"Hello World");//Write text'Hello World' in first row } ภาพจำลองการทำงานด้วยโปรแกรม Proteus อ้างอิง https://electrosome.com/lcd-pic-interfacing/

arduino 16

รูปภาพ
              ใบรายงานผลการปฏิบัติงาน Code #include <Stepper.h>     //  การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ #include "Keypad.h"  #define STEP_ANGLE_4STEP 32 //360/11.25 degree    //    ใช้เพื่อตั้งชื่อค่าคงที่ #define STEP_OUT_WITH_GEAR 2048 //32*64 Stepper stepper(STEP_ANGLE_4STEP,8,10,9,11); char keys[4][4]={    // เก็บข้อมูลที่  หน่วยความจำ  1  ไบต์   {'7','8','9','A'},   {'4','5','6','B'},   {'1','2','3','C'},   {'*','0','#','D'}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; int speedmotor = 400;    / /  ตัวแปรพื้นฐานที่เก็บตัวเลขโดยไม่มีจุดทศนิยม int dirmotor = 1; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); //ฟังก์ของkeypad void setup()      //  ฟังก์ชั่นใช้ในการประกาศค่าเริ่มต้น   { } void loop()   //  ฟังก์ชั่นใช้ในการเขียนโค้ดโปรแกรมการทำงานของ...

arduino 15

รูปภาพ
                ใบรายงานผลการปฏิบัติงาน Code #include <LedControl.h>      //  การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ #include <DHT11.h>     int pin=4;        / /  ตัวแปรพื้นฐานที่เก็บตัวเลขโดยไม่มีจุดทศนิยม DHT11 dht11(pin);   //ฟังก์ชั่นพิเศษของ   DHT11.h LedControl lc=LedControl(8,10,9,1);     //ฟังก์ชั่นของ lcd void show2digit(int h,int t)    // การเขียนฟังชั่นขึ้นมาโดยตั้งชื่อว่า  show2digit {    int seg1,seg2,seg3,seg4;   seg1 = h%10;   seg2 = h/10;   lc.setDigit(0,4,seg1,false);    lc.setDigit(0,5,seg2,false);   seg3 = t%10;   seg4 = t/10;   lc.setDigit(0,0,seg3,false);    lc.setDigit(0,1,seg4,false);   delay(300); } void setup()    //  ฟังก์ชั่นใช้ในการประกาศค่าเริ่มต้น {   Serial.begin(9600);   //ประกาศการใช้งาน...

arduino 14

รูปภาพ
ใบรายงานผลการปฏิบัติงาน Code #include <LedControl.h>      //  การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 11    //    ใช้เพื่อตั้งชื่อค่าคงที่ OneWire oneWire(ONE_WIRE_BUS);     // ฟังก์ชั่นพิเศษของ  OneWire.h DallasTemperature sensors(&oneWire); float Tfloat;     //   ตัวแปรชนิด floating-point หรือตัวแปรที่มีจุดทศนิยม long Tint;     เป็นตัวแปรจำนวนเต็มแบบขยายโดยไม่มีจุดทศนิยม เก็บค่าแบบ 32 bit   LedControl lc=LedControl(8,10,9,1);  void show6digit(int num)    // การเขียนฟังชังก์ชั่นขึ้นมาโดยใช้ชื่อว่า  show6digit {   int seg1,seg2;   seg2 = (((((num%100000)%10000)%1000)%100)/10);   seg1 = (((((num%100000)%10000)%1000)%100)%10);   lc.setDigit(0,0,seg1,false);    if (num>=10)       lc.setDigit(0,1,seg2,fal...

arduino pir sensor

รูปภาพ
                 ใบรายงานผลการปฏิบัติงาน Code #include <LiquidCrystal_I2C.h>      //  การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ LiquidCrystal_I2C lcd(0x27,16,2);   //ฟังก์ชั่นของ lcd กำหนดให้ ตัวอักษรที่16 แถวที่2 int PIRpin = 8;    / /  ตัวแปรพื้นฐานที่เก็บตัวเลขโดยไม่มีจุดทศนิยม void setup()    //  ฟังก์ชั่นใช้ในการประกาศค่าเริ่มต้น   {    lcd.begin();  // ไฟเเบคไลท์     pinMode(PIRpin,INPUT);     // การกำหนดหน้าที่ของขาว่าเป็นอินพุตหรือเอาต์พุต   lcd.home();     lcd.print("Waiting for PIR");   delay(10000);       // หน่วงเวลา   lcd.clear();            // ล้างหน้าจอ } void loop()     //  ฟังก์ชั่นใช้ในการเขียนโค้ดโปรแกรมการทำงานของArduinoเป็นฟังก์ชั่นการวนลูปไปเรื่อยๆ  {    int x = digitalRead(PIRpin);...

arduino sonar

รูปภาพ
  ใบรายงานผลการปฏิบัติงาน Code #include <LiquidCrystal_I2C.h>   //  การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ LiquidCrystal_I2C lcd(0x27,16,2);   //ฟังก์ชั่นของ lcd กำหนดให้ ตัวอักษรที่16 แถวที่2 int triggerPin = 13;  //  ตัวแปรพื้นฐานที่เก็บตัวเลขโดยไม่มีจุดทศนิยม int echoPin = 12; long duration,distCM,temp_distCM=0;  //  เป็นตัวแปรจำนวนเต็มแบบขยายโดยไม่มีจุดทศนิยม เก็บค่าแบบ 32 bit   void setup()       //  ฟังก์ชั่นใช้ในการประกาศค่าเริ่มต้น  {    lcd.begin();   // การทำงานเริ่มต้นของ lcd    lcd.setCursor(0,0);   //ใ ช้สั่งให้แสดงเคเซอร์บนหน้าจอ ตัวอักษรที่0เเถว0   lcd.print("Dist =      cm");        pinMode(triggerPin,OUTPUT);     // การกำหนดหน้าที่ของขาว่าเป็นอินพุตหรือเอาต์พุต   pinMode(echoPin,INPUT); } void loop()  {   digitalWrite(triggerPin,LOW);     // ทำหน้า...