---
# System prepended metadata

title: 介面 實驗八

---

# 介面 實驗八
## 工作日誌
機械3A
孫颯馬
### 遭遇問題
### 流程
1. 微動開關感測實驗(開關)
2. 電位計感測實驗(電阻)
3. 光敏電阻感測實驗(電阻)
4. 薄膜壓力感測實驗(電阻)
5. 電容麥克風感測實驗(電容)
6. 轉速發電機感測實驗(電壓源)
7. 光電晶體感測實驗(電流源)
8. 霍爾磁場感測(電流激發-電壓值量測)


###  實驗數據
## 1. 微動開關感測實驗(開關)
:::info
![](https://i.imgur.com/I99rfo8.png)
:::

:::spoiler Click Me
the left side
![](https://i.imgur.com/uMUexZa.png)
the right side
![](https://i.imgur.com/HOdhNKp.png)

:::


## 2. 電位計感測實驗(電阻)
:::info
![](https://i.imgur.com/iB1PfeF.png)

:::
:::spoiler Click
![](https://i.imgur.com/jSPjXFW.png)
最小角度
![](https://i.imgur.com/xqcDVAt.png)
最大角度
![](https://i.imgur.com/Z3gux7X.png)
右1K
![](https://i.imgur.com/x9An2cE.png)
:::

## 3. 光敏電阻感測實驗(電阻)
:::spoiler Click
沒照光(5.12V)
![](https://i.imgur.com/mdxyHJv.png)
照光(1.76V)
![](https://i.imgur.com/uimgT9O.png)

:::

## 4. 薄膜壓力感測實驗(電阻)
:::spoiler Click
沒壓(4.68V)
![](https://i.imgur.com/OxLO2BK.png)
壓1kg(3.68V)
![](https://i.imgur.com/mc7N3zS.png)
壓2kg(1.39V)
![](https://i.imgur.com/3PVgeUZ.png)
:::

## 5. 電容麥克風感測實驗(電容)
:::info
![](https://i.imgur.com/sYN2h72.png)
:::
:::spoiler Click
833Hz
![](https://i.imgur.com/knWykGy.png)
3KHz
![](https://i.imgur.com/3BOswpI.png)

:::

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

:::
:::spoiler Click
沒轉(4.95V)
![](https://i.imgur.com/30yfCax.png)
0.75A(2.78V)
![](https://i.imgur.com/TeZLxB7.png)
0.92A(0V)
![](https://i.imgur.com/8iqWFK3.png)
:::

## 7. 光電晶體感測實驗(電流源)
:::info
![](https://i.imgur.com/DuyuuH2.png)

:::
:::spoiler Click
0.2mA
![](https://i.imgur.com/on3jcam.png)
0.6mA
![](https://i.imgur.com/sP5cKFq.png)
1.2mA
![](https://i.imgur.com/gJoGa0f.png)
遮住
![](https://i.imgur.com/mYm3Hbj.png)

:::

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

:::
:::spoiler Click
![](https://i.imgur.com/vC2QheV.png)
![](https://i.imgur.com/VgmfIu1.png)
![](https://i.imgur.com/gtPAS67.png)
![](https://i.imgur.com/87r5ZFQ.png)
:::

## 驗收
### 驗收題目
![](https://i.imgur.com/1inNriw.jpg)
實驗數據
:::spoiler 接線
![](https://i.imgur.com/aNr0TVI.png)
:::
:::spoiler 程式
#include "c4mlib.h"
#define F_CPU 11059200UL

uint16_t temp = 0;
float volt = 0;
int resistance = 0;
int current = 1;
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,1);//禁能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(2000);
	}
}
void meansure(void)
{
	REGFPT(&ADMUX,0x1F,0,0x00);//設定輸入通道ADC1
	REGFPT(&ADCSRA,0x40,6,1);//觸發 ADC 轉換
	REGGET(&ADCL, 2, &temp);//讀取 10 位元 uint16_t型態轉換結果
}

void record(void)
{
	volt = temp*5.12/1024;
	resistance = (5.12-volt)*1000/current;
	
	if (volt!=0)
	{
		printf("V= %.2f V\n",volt);
		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
	}
}

:::
:::spoiler 驗收影片
https://youtu.be/CawufRR7sKA
:::



