---
# System prepended metadata

title: 介面lab08

---

# 介面lab08
## 工作日誌
* 12/02閱讀講義


## 實驗數據
###    1. 微動開關感測實驗(開關)
* 微動開關接電源側 按下時HI
![](https://i.imgur.com/LutRK2N.png)
* 微動開關接地側 按下時LO
![](https://i.imgur.com/BPwFHKD.png)
###    2.1電位計感測實驗(電阻)
![](https://i.imgur.com/je27ofn.png)
* 會超過ADC量測範圍
![](https://i.imgur.com/2evFaVS.png)
###    2.2光敏電阻感測實驗(電阻)
![](https://i.imgur.com/LfVUHKM.png)


###    2.3薄膜壓力感測實驗(電阻)
![](https://i.imgur.com/DiMoFUC.png)

###    3.電容麥克風感測實驗(電容)
![](https://i.imgur.com/AWSMJ7O.png)
![](https://i.imgur.com/7jLf5S4.jpg)
![](https://i.imgur.com/ewFtCyz.jpg)
![](https://i.imgur.com/vPlye3b.jpg)
![](https://i.imgur.com/3qN4eHy.jpg)

* ADC讀取數據，難以計算頻率響應
![](https://i.imgur.com/Jn2akm9.png)


###    4.轉速發電機感測實驗(電壓源)
![](https://i.imgur.com/2eL3yar.png)



###    5.光電晶體感測實驗(電流源)


| 輸入電壓 | 0    | 1.5  | 2    | 2.5  | 3.0  | 3.5  | 4.0    |  5.0   |
| -------- | ---- | ---- | ---- | ---- | ---- | ---- | --- | --- |
| 量測電壓 | 4.71 | 4.51 | 4.71 | 3.02 | 2.37 | 1.46 |  0.60   |  0.18   |

###    6.霍爾磁場感測(電流激發-電壓值量測)
![](https://i.imgur.com/bsRE7Ph.png)

## 驗收
### 驗收題目
![](https://i.imgur.com/Ay78Msi.jpg)
### 驗收成果
```c
#include "c4mlib.h"
#define F_CPU 11059200UL

uint16_t singletrm = 0;
float singleDigit = 0;
int resistance = 0;
int current = 1;

void meansure(void)
{
	REGFPT(&ADMUX,0x1F,0,0x00);//設定輸入通道ADC1
	REGFPT(&ADCSRA,0x40,6,1);//觸發 ADC 轉換
	REGGET(&ADCL, 2, &singletrm);//讀取 10 位元 uint16_t型態轉換結果
}

void record(void)
{
	singleDigit = singletrm*5.12/1024;
	resistance = (5.12-singleDigit)*1000/current;
	
	if (singleDigit!=0)
	{
		printf("V= %.2f V\n",singleDigit);
		printf("current= %d mA\n",current);
		printf("resistance = %4d ohm\n", resistance);
		printf("-----------------\n");
	}
	
	if (resistance>500)
	{
		current = 1;
		REGFPT(&PORTD,0xC0,0,0x80);//1mA
	}
	if (resistance<400)
	{
		current = 10;
		REGFPT(&PORTD,0xC0,0,0x40);//10mA
	}
	
	
}


int main(void)
{
	C4M_DEVICE_set();
	
	/*ADC設定旗標群*/
	REGFPT(&ADMUX,0x1F,0,0x1F);//設定輸入通道Calibrate
	REGFPT(&ADMUX,0xC0,6,0);//設定參考電壓外部參考
	REGFPT(&ADMUX,0x20,5,0);//設定10位元轉換
	REGFPT(&ADCSRA,0x07,0,2);//設定工作時脈除頻4
	REGFPT(&ADCSRA,0x20,5,0);//禁能觸發轉換
	REGFPT(&ADCSRA,0x08,3,0);//禁能ADC中斷
	REGFPT(&DDRF,0x0F,0,0);//設定ADC接腳為輸入
	
	REGFPT(&ADCSRA,0x80,7,1);//致能ADC
	REGFPT(&ADCSRA,0x40,6,1);//觸發 ADC 轉換
	
	REGFPT(&DDRD,0xC0,0,0xC0);
	REGFPT(&PORTD,0xC0,0,0x80);//1mA
	
	
	while(1){
		meansure();
		record();
		_delay_ms(500);
	}
	
	
	
}
```
[影片_可變電阻_HMI](https://ncu365-my.sharepoint.com/:v:/g/personal/oreo900930_office365_ncu_edu_tw/EVXbfVxrDn1Du1WjgSNVB_EBSf9CHmZJ0jwyIsKtHpmQ8A?e=r1hxcz)
[影片_可變電阻_電路](https://drive.google.com/file/d/1p1uV6rlEOK7aT_RSBqzgyMgNB1FAo9Q8/view?usp=share_link)
[影片_單電阻測量](https://ncu365-my.sharepoint.com/:v:/g/personal/oreo900930_office365_ncu_edu_tw/ESXzWNegmcdKjJoc5imN_N0BOrUwSf8uZ45ngsL5Ewd0Jw?e=2VnR7S)