洪嵐峰 發表於 2023-4-23 08:59:47

EM78P156NP

EM78P156NP 是一款低成本的 8 位元單晶片微控制器,它可以用來製作萬用測試表,具有勾錶功能,可以測試電容、電阻、電壓和電流,並附帶示波器螢幕。

以下是所需的零件:

所需零件:

EM78P156NP 微控制器
LCD 示波器螢幕
電容
電阻
電位器
NPN 電晶體
PNP 電晶體
二極體
連接線
電池或直流電源
其他零件(如按鈕、開關等)
連結腳位:

P0.0 - P0.7:EM78P156NP 的 8 個 I/O 腳位,用於連接顯示器、按鈕、電容、電阻和其他元件。
P1.0 - P1.3:EM78P156NP 的 ADC 輸入腳位,用於測量電壓和電流。
P1.4 - P1.7:EM78P156NP 的特殊功能腳位,用於連接 LCD 示波器螢幕。
程式碼:
以下是示範程式碼,可以在 EM78P156NP 微控制器上運行,以實現萬用測試表的基本功能。

請注意,這只是一個示例,您需要根據您的具體要求進行修改和擴展。

arduino
Copy code
#include <em78p156np.h>

// 定義 LCD 示波器螢幕的 I/O 腳位
#define LCD_RS P1_4
#define LCD_RW P1_5
#define LCD_E P1_6
#define LCD_DB7 P1_7
#define LCD_DB6 P1_0
#define LCD_DB5 P1_1
#define LCD_DB4 P1_2

// 定義測試元件的 I/O 腳位
#define CAP_TEST P0_0
#define RES_TEST P0_1
#define VOL_TEST P1_0
#define CUR_TEST P1_1

void init_lcd(void)
{
    // 初始化 LCD 示波器螢幕
    // ...
}

void lcd_write_string(char *str)
{
    // 在 LCD 示波器螢幕上顯示字符串
    // ...
}

void test_cap(void)
{
    // 測試電容
    // ...
}

void test_res(void)
{
    // 測試電阻
    // ...
}

void test_vol(void)
{
    // 測試電壓
    // ...
}

void test_cur(void)
{
    // 測試電流
    // ...
}



#include <em78p156np.h>

// 定義 LCD 示波器螢幕的 I/O 腳位
#define LCD_RS P1_4
#define LCD_RW P1_5
#define LCD_E P1_6
#define LCD_DB7 P1_7
#define LCD_DB6 P1_0
#define LCD_DB5 P1_1
#define LCD_DB4 P1_2

// 定義測試元件的 I/O 腳位
#define CAP_TEST P0_0
#define RES_TEST P0_1
#define VOL_TEST P1_0
#define CUR_TEST P1_1

void init_lcd(void)
{
    // 初始化 LCD 示波器螢幕
    // ...
}

void lcd_write_string(char *str)
{
    // 在 LCD 示波器螢幕上顯示字符串
    // ...
}

void test_cap(void)
{
    // 測試電容
    unsigned int count = 0;
    CAP_TEST = 1;
    while (CAP_TEST == 1) count++;
    lcd_write_string("C = ");
    lcd_write_string(count);
    lcd_write_string(" pF");
}

void test_res(void)
{
    // 測試電阻
    unsigned int count = 0;
    RES_TEST = 1;
    while (RES_TEST == 1) count++;
    lcd_write_string("R = ");
    lcd_write_string(count);
    lcd_write_string(" ohm");
}

void test_vol(void)
{
    // 測試電壓
    unsigned int count = 0;
    VOL_TEST = 1;
    while (VOL_TEST == 1) count++;
    lcd_write_string("V = ");
    lcd_write_string(count);
    lcd_write_string(" V");
}

void test_cur(void)
{
    // 測試電流
    unsigned int count = 0;
    CUR_TEST = 1;
    while (CUR_TEST == 1) count++;
    lcd_write_string("I = ");
    lcd_write_string(count);
    lcd_write_string(" mA");
}

void main(void)
{
    // 初始化 LCD 示波器螢幕
    init_lcd();

    // 無限循環,持續測試各種元件
    while (1) {
        test_cap();
        test_res();
        test_vol();
        test_cur();
    }
}
頁: [1]
查看完整版本: EM78P156NP