• 検索結果がありません。

sensor light pic12f1822

N/A
N/A
Protected

Academic year: 2018

シェア "sensor light pic12f1822"

Copied!
4
0
0

読み込み中.... (全文を見る)

全文

(1)

PICkit3

ICSPCLK

ICSPDAT VSS Ground

VDD MCLR/VPP

Breadboard Challenge 2017

[

BC17-

04]

マイコン・センサ・ライト

チャレンジ1 マイコンにプログラムを書き込む

実体配線図

+

-部品

PIC 12F1822 PIC

12F1822

マイコン

(2)

/*

* LED1 : PIN 7 (RA0) : 1-ON, 0-off *

*

* ANALOG PORT : PIN 3 (AN3) *

*/

#include <xc.h> #include <stdint.h>

#define ledOn() (RA0 = 1) #define ledOff() (RA0 = 0)

#define led() (RA0 ^= 1) // LEDを点滅する

// Configuration 1

#pragma config FOSC = INTOSC // Internal Clock #pragma config WDTE = OFF // NO Watchdog timer

#pragma config PWRTE = ON // Program start at Power on after 64ms #pragma config MCLRE = OFF // No Ext Reset, Enable RA3 input pin #pragma config CP = OFF // No Code protect

#pragma config CPD = OFF // No Data Protect #pragma config BOREN = ON // Brown out enable #pragma config CLKOUTEN = OFF // CLKOUT as RA4 #pragma config IESO = OFF // No Internal External clock #pragma config FCMEN = OFF // No FCM

// Configuration 2

#pragma config WRT = OFF // No Write Protect #pragma config PLLEN = OFF // No PLL

#pragma config STVREN = ON // Reset on Stack over / under flow #pragma config BORV = HI // Watch Voltage drop (2.5V = HI) #pragma config LVP = OFF // No Low Voltage Programming

void wait(volatile uint32_t i) {

while (i-- > 0); }

void initIO(void) // I/Oポートの初期化 {

OSCCON = 0b01110010 ; // Internal clock 8MHz

OPTION_REG = 0b00010000 ; // Weak Pull up Resistor RA4-OFF,       others ON

ANSELA = 0b00010000 ; // Analog PORT AN3(RA4) TRISA = 0b00011000 ; // Input : RA34, Output: others WPUA = 0b00001000 ; // Weak pullup : RA3

PORTA = 0b00000000 ; // Initialize PORTA }

void main(void) {

int i;

uint8_t adc_value; // 明るさを表す数値

initIO(); // I/Oポートの初期化 initAdc8(); // A/Dコンバータの初期化 initTimer0(); // Timer0の初期化

// LEDが3回点滅 for (i = 0; i < 6; i++) { led();

wait(10000); }

ledOff();

while (1) {

adc_value = getAdc8(); // A/Dコンバータで明るさを検出 if (adc_value < 220) { // 明るいときは LED消灯 ledOff();

} else {

// 暗いときは60秒間点灯する

for (T0count = 0 ; T0count < TIMER0_1SEC * 60; ) { ledOn();

}

// 明るくなるまでLEDを消灯して待つ while (adc_value >= 220) { ledOff();

adc_value = getAdc8(); // A/Dコンバータで明るさを検出 }

} } }

Breadboard Challenge 2017

[

BC17-

04]

マイコン・センサ・ライト

マイコンに書き込むプログラムのソースコード

void initAdc8(void) // A/Dコンバータの初期化 {

ANSELA = 0b00010000; //RA4 Analog port,         others digital port ADCON0 = 0b00001101; //0:unimp,         00011:AN3,

        0:GOnDone, 1:ADC enable ADCON1 = 0b01000000; //0:Left jutified (8bit res.), //100:Fosc/4 ,0:Reserved, // 00:AVDD=VREF CM1CON0 = 0x00; //Comparator disable }

uint8_t getAdc8(void) // 精度8bitでA/D変換 {

uint8_t d; //ADC wait(10); GO_nDONE = 1; while (GO_nDONE); d = ADRESH; return d; }

void initTimer0(void) // タイマの初期化 {

OPTION_REG &= 0b11111000; // Clear Prescale OPTION_REG |= 0b00000111; // Prescaler 1:256

TMR0 = 0; // initialize Timer0

TMR0IF = 0; // Timer0 interrupt enable TMR0IE = 1; // Enable Timer0 Interrupt GIE = 1; // Enable Interrupt

}

/*

* 1 interrupt

* => 1/8 * 4 (instruction exec clock) * 256(prescaler) * 256 * = 32768 us ,

* 1 sec = 1 / 32768e-6 = 30.517 counts */

static volatile unsigned int T0count; #define TIMER0_1SEC 30

void interrupt InterFunction( void ) // 割り込み関数

{

// Timer0 Interrupt

if (TMR0IF == 1) { // Timer0割り込みが発生したとき TMR0 = 0;

T0count++; TMR0IF = 0; }

(3)

A

A

150Ω

茶緑茶金

部品

A

-+4.5V

PIC 12F1822

Breadboard Challenge 2017

[

BC17-

04]

マイコン・センサ・ライト

(4)

E

E

100kΩ

茶黒黄金

部品

PIC 12F1822

Breadboard Challenge 2017

[

BC17-

04]

マイコン・センサ・ライト

チャレンジ3 明るさのセンサをつける

E

参照

関連したドキュメント

Appeon and other Appeon products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Appeon Limited.. SAP and other SAP

Their basic components are the representation of candidate solutions to the problem in a “genetic” form, the creation of an initial, usually random population of solutions,

Verification of Ptime Reducibilityfor System F termsVia Dual Light Affine Logic – p.12/32.3. Difficulty

“Breuil-M´ezard conjecture and modularity lifting for potentially semistable deformations after

In this chapter, we shall introduce light affine phase semantics, which is meant to be a sound and complete semantics for ILAL, and show the finite model property for ILAL.. As

As a general remark, sensor fault detection results obtained with OKID are similar to those obtained with a traditional Kalman filter, but, with the proposed method, the OKID

Theorem 8 (Polynomial time strong normalization) Let t be a lambda- term which has a typing derivation D of depth d in DLAL.. This result holds independently of which reduction

With hysteresis not enabled (see ALS_CONFIG register), the ALS_TH registers set the upper and lower interrupt thresholds of the ambient light detection window. Interrupt