#include "uart.h" // #define RTC8583 0xA0 // RTC address #define CTRL 0x00 // RTC register notation START/STOP #defin

Similar documents
#define HOUR 0x04 #define DAY 0x05 #define WEEKDAY 0x06 #define MONTH 0x07 #define YEAR 0x08 #define CKOUT 0x0D #define CTRLT 0x0E // CLKOUT // TIMER

3 4 PIC

untitled

Arduino UNO IS Report No. Report Medical Information System Laboratory

DL1720/DL1740ディジタルオシロスコープユーザーズマニュアル

スライド 1

PowerPoint プレゼンテーション

ESP32-KEY-KIT-R1 (ESP-WROOM-32 ) Copyright c 2

スライド 1

untitled

thesis.dvi

割り込み 今までのプログラムは 順番にそって命令を実行していくのみ それはそれで良いが 不便な場合もある 例えば 時間のかかる周辺機器を使う場合 その周辺機器が動作を終了するまで CPU は待たなければいけない 方法 1( ポーリング ) 一定時間毎に 周辺機器の動作が終了したか調べる 終了していれ

Microsoft Word - 工学ゼミ3_テキスト

Timers_JP.fm

ESP8266-CORE-R Copyrig

スライド 1

(Making the electronic circuit with use of micro-processor)

1 4 8 (DC) PWM.

PIC

EQUIUM EQUIUM S5010 1

Microsoft Word - 工学ゼミ3_テキスト

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

スライド 1

< D A0>

,, ( ) 5 ma ( ) 5V V 5 6 A B C D E F G H I J , LED LED, LED, 7 LED,, 7 LED ( ) V LED VCC 5V 7 LED VCC f g f a g b a b c e d e d c dp dp VCC (

3 1EEPROMElectrically Erasable PROM PROMProgrammable ROM 2 EEPROM 3


// USB_CNC_Machine リモート PIO 端末プログラムのメイン関数およびユーザアプリ部 // 編集作成 by Takehiko Inoue /*********** メイン関数 ***************************/ #pragma code

Lab GPIO_35 GPIO

TOS7200 CD-ROM DUT PC 1.0X p.15 NEMA Vac/10 A [85-AA-0003] m : CEE7/7 : 250Vac/10 A [85-AA-0005] : GB1002 : 250Vac/10A [ ] 2016

スライド 1

XMOS プログラミング入門 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 初版 1 刷発行時のものです.

1

Microsoft PowerPoint - 第8α章.ppt [互換モード]

Microsoft Word - マイコンを用いた信号# doc

スライド 1

mbed祭りMar2016_プルアップ.key

スライド 1

NL-20取扱説明書_操作編

slide

【注意事項】RX Driver Package、 RXファミリ RTC モジュール Firmware Integration Technology

MPL115A

DL1700Eシリーズ ディジタルオシロスコープ ユーザーズマニュアル

1 1 TA, ,9 1. ( 2. TM TM GUI TM 1. P7-13 TM Notepad, Meadow, ( P109 ). 2. (shisaku01/sys test)

Microsoft Word - PIC-P14マニュアル.doc

DS30292A-J-page 2 Preliminary 2000 Microchip Technology Inc. PIC16F876/

mbed_library_study_meeting_v1.0.key

S1C17W12 S1C17W13 (WDT2) (RTCA) 16 (T16) 16PWM (T16B) SQFN7-48pin TQFP12-48pin SQFN7-48pin NMI, NMI/ Hz, / / / // / 1, 3 SPIA 2 / PWM PWM : 2/ (

94

C言語によるPIC(16F88)プログラミング実習テキスト

2

o4hd200j.pdf

橡EN1165.PDF

TH-42/47/55LF6J,TH-42/47/55LF60J

CM1-GTX

PBASIC 2.5 PBASIC 2.5 $PBASIC directive PIN type New DEBUG control characters DEBUGIN Line continuation for comma-delimited lists IF THEN ELSE * SELEC

NL-22/NL-32取扱説明書_操作編

スライド 1

回路 : Vdd GND 回路図と呼べるようなものではありません オシレータは外部 ( セラミック発振子 ) なので GP4 と GP5 は使えません 四角の枠内はモジュールなので ここから VDD GND TX RX の4 本をつなぐだけです 測定端子 (GP0) は 1MΩの抵抗と 2MΩの半固

2

AutomaticTelegraphKeyProject.c

RR-US470 (RQCA1588).indd

PIC

1 122

PowerPoint プレゼンテーション

10ビットPWM機能によるデューティパルス出力

Microsoft Word - SU1204教本(Driver)原稿.docx

2

割り込み 今までのプログラムは 順番にそって命令を実行していくのみ それはそれで良いが 不便な場合もある 例えば 時間のかかる周辺機器を使う場合 その周辺機器が動作を終了するまで CPU は待たなければいけない 方法 1( ポーリング ) 一定時間毎に 周辺機器の動作が終了したか調べる 終了していれ


1 142

Express5800/320Fc-MR

tutorial_lc.dvi

アプリケーションノート AS-E402サンプルプログラム

RT300i/RT140x/RT105i 取扱説明書

Untitled

XC9500 ISP CPLD JTAG Port 3 JTAG Controller In-System Programming Controller 8 36 Function Block Macrocells to 8 /GCK /GSR /GTS 3 2 or 4 Blocks FastCO

FreeBSD 1

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM

RT300/140/105シリーズ 取扱説明書

GR-SAKURA-SAのサンプルソフト説明

スライド 1

TH-47LFX60 / TH-47LFX6N

電磁流量計 WZ-C Modbus RTU 通信仕様書 ver.8.225

DV-RA1000HD_Jpn(b)

USB モジュール

RTX830 取扱説明書

VHDL VHDL VHDL i

AN-1077: ADXL345 Quick Start Guide

inst.c

8ビットデータバスでアクセスする場合は、16ビットレジスタを上位バイト、下位バイトに分けてアクセスします

81 /******************************************************************************/ 82 /* スレーブアドレスの設定 */ 83 /*****************************************

Taro11-表紙と目次.PDF

Express5800/R320a-E4/Express5800/R320b-M4ユーザーズガイド

For_Beginners_CAPL.indd

Microsoft Word - 本文.doc

2008 DS T050049

untitled

PIN S 5 K 0 K 1 K 2 K 3 K 4 V DD V 0 V 1 V 2 V SS OSC SEG 32 SEG 31 SEG 30 SEG 29 SEG 28 SEG 27 SEG 26 SEG 25 SEG 24 SEG 23 SEG 22 SEG 21 SEG 20 SEG 1

Express5800/R110a-1Hユーザーズガイド

Transcription:

****************** RTC clock with thermo & moisture meter by PIC12F1829 LCD display and serial output with internal clock By nobcha all right reserved Reffer to 05/22/2014 PIC16F1827+RTC8564NB + SHT-11 + 9600bps Serial Reffer to 11/01/2014 PIC16F1827 + RTC8583 + sw 11/02/2014 PIC16F1829 + LCD + RTC8583 + SHT-11 -------------------------------------------- RA0: LCD RS bit 0 RA1: LCD EN bit 0 RA2: Clock out from INT 1 RA3: SW1 SET_sw 1 RA4: SW2 UP_sw 1 RA5: Mon LED 0 RB4: SDA 1 RB5: UART RX 1 RB6: SCL 1 RB7: UART TX 0 RC0: SHT-11 SCK 1 RC1: SHT-11 DATA pulling up by 103 1 RC2-5: SC1602は4ビットモードで接続 0 RC6: CCCP4:Charge pump source 0 RC7: SW3 Down SW 1 ------------------------------------------------- SC1602 pin connection via 4bit mode #1 Vdd=5V #2 Vss=GND #3 LCD contrust center of 2k VOL #4 RS RB7 #5 R/W GND #6 EN RB6 #11-14 DATA RA0-3 OSC INT 16MHz Development Circumstance MPLAB IDE V8.86 HiTECH C V9.83 ******************* #define _XTAL_FREQ 16000000 #define PIC_CLOCK 16000000 #include <htc.h> #include <stdio.h> #include "lcd.h" #include "mssp_i2c.h" #include "sht.h" 1

#include "uart.h" //--------------------------------- #define RTC8583 0xA0 // RTC address #define CTRL 0x00 // RTC register notation START/STOP #define SECOND 0x02 #define MINUTE 0x03 #define HOUR 0x04 #define DAY 0x05 #define MONTH 0x06 #define TIMER 0x07 // TIMER CONTROL #define second RTC_DATA[5][0] #define minute RTC_DATA[4][0] #define hour RTC_DATA[3][0] #define day RTC_DATA[2][0] #define month RTC_DATA[1][0] #define year RTC_DATA[0][0] #define weekday RTC_DATA[6][0] #define Set_sw RA3 #define Down_sw RC7 #define Up_sw RA4 //---------------------------------- #define Heart_beat LATA5 CONFIG( FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF ); CONFIG( WRT_OFF & PLLEN_OFF & STVREN_ON & LVP_OFF ); // Grobal variables & data unsigned char i ; char wkdname[4]; unsigned char set_pos, clk1hzint=0, PBuf=0; char Msg1[] = "RTC+RT+RH SER"; char Str[8]; //------------------- // Default/Max/Min table unsigned char RTC_DATA[7][3]={{0x14,0x30,0x05, // Year->Day 2

{0x12,0x12,0x01, // month:6 stacked weekday {0x31,0x31,0x01, // day:5 stacked year {0x23,0x23,0x00, // hour:4 24hour:0 {0x59,0x59,0x00, // minute:3 {0x50,0x59,0x0, // second:2 {0x0,0x6,0x0; // Weekday->Month // Default,Max,Min // LCD cursor position //..._.._.._ 2014.10.12 //._.._.._.._ 23:59:59Sun char LCD_POS[7]={0x03,0x06,0x09,0x41,0x44,0x47,0x49; //---------------------- unsigned char i, j, zero_sup,disp_data ; unsigned char bdat_l,bdat_h, bdat_crc; int ADValHR,ValHR10,ADValTmp,wdat ; // Prototyping functions void rtc_write(unsigned char, unsigned char); char rtc_read(unsigned char ); void lcd_hex(unsigned char ); void lcd_wkd(unsigned char); void rtc_writestr(void); void rtc_readstr(void); void rtc_disp(void); unsigned char bctob(unsigned char ); unsigned char btobc(unsigned char ); void data_inc(unsigned char ); void data_dec(unsigned char ); void mssp_init(void); void interrupt clk1hz(void); void putch(unsigned char); // --------------------------------------- // main void main(){ //------------------------------ PORTA = 0b00100000; ANSELA = 0b00000000; // TRISA = 0b00011100; /* RA0: LCD RS bit 0 RA1: LCD EN bit 0 // PORT clear // all digital 3

RA2: Clock out from INT 1 RA3: SW1 SET_sw / reset 1 RA4: SW2 UP_sw 1 RA5: Mon LED 0 */ PORTB = 0b00000000; ANSELB = 0b00000000; // TRISB = 0b01110000; /* RB4: SDA 1 RB5: UART RX 1 RB6: SCL 1 RB7: UART TX 0 // PORT clear // all digital */ LATC = 0b00000000; // LATC RESET TRISC = 0b10000010; // /* RC0: SHT-11 SCK 0 RC1: SHT-11 DATA pulling up by 103 1 RC2-5: SC1602 は 4 ビットモードで接続 0 RC6: CCCP4:Charge pump source 0 RC7: SW3 Down SW 1 */ ANSELC = 0b00000000; // all digital //-------------------------------------------- // OSCCON = 0b01111000; /* ^^^^------------IRCF16MHz ^----------SCS:int */ OPTION_REG =0b00000000; /* ^------------Weak up disable ^----------TMR0CS:RA2/T0CKI ^---------TMR0SE:H->L of RA2/T0CKI ^--------PSA:assinged ^^^-----PS:1:4 */ INTCON=0; T1CON = 0b11000000; DIS,T1SYNC, TMR1 off // T1GCON = 0b00000000; PIR1 = 0b00000000; 0,TMR2IF 0,TMR1IF 0 // INT off // Timer1 CPS, T1CKPS:00, T1OSC // ADIF 0,RCIF 0,TXIF 0,SSPIF 0,CCP1IF 4

CM1CON0 = 0x00000000; CM2CON0 = 0x00000000; // // //CCP4 PWM initializing (83.8KHz on RB3 @16MHz) CCP4CON = 0b00001111; // use PWM mode CCPR4L = 0x0c; // duty is 50% CCPTMRS = 0; // Select TMR2 // TMR2 initilizing T2CON = 0b00000100; // POSTSCALE 1:1,TMR2 ON, PRESCALE 1:1 /* LCD 低電圧駆動ではかなりの立ち上げ余裕必要 */ lcd_init(); lcd_goto(0x00); lcd_puts(msg1); delay_ms(20); mssp_init(); SHTInit(); // LCD initialize // select first line // Display for SC1602 init_uart(); lcd_putch(0x40); rtc_readstr(); // get RTC data if(rtc_data[0][0]==0){ // if no back up RTC_DATA[0][0]=0x12; // set default value RTC_DATA[1][0]=0x09; RTC_DATA[2][0]=0x05; lcd_putch(0x40); rtc_disp(); // display rtc status rtc_writestr(); // set RTC > 1Hz INT start INTCON = 0b10010000; // GIE:1, INTE:1 while(1){ 5

if(set_sw==0){ delay_ms(150); if(set_sw==0){ set_pos=0; second // if RA3==0 Set mode // YEAR->Month->day->hour->minuts-> rtc_readstr(); // get RTC data while(set_pos<7){ // set_pos:5->0 lcd_goto(lcd_pos[set_pos]); delay_ms(150); while(up_sw&down_sw&set_sw){ // Wait Switch on delay_ms(150); // Wait a time if(up_sw==0){ data_inc(set_pos); if(down_sw==0){ data_dec(set_pos); if(set_sw==0){ set_pos++; rtc_disp(); // display rtc scratch status rtc_writestr(); delay_ms(100); if(clk1hzint==1){ clk1hzint=0; rtc_readstr(); rtc_disp(); // Humidity reading SHTTSSeq(); SHTWrite(0x05); // set RTC // flag clear // get RTC data // display rtc status // TSシーケンス発行 // measure humidity コマンド送信 // 変換完了待ち while((sht_port & (1<<bitDATA))) { // A-D 変換完了を待つ bdat_h = SHTRead(0); bdat_l = SHTRead(0); bdat_crc = SHTRead(1); // read high byte(ack) // read low byte(ack) // read CRC(NOACK) ADValHR = ((int)bdat_h << 8) bdat_l; // 16ビットに合成 ValHR10 = CalcHR10(ADValHR); // 工学数値へ変換 sprintf(str,"%d.%d%%",valhr10/10,valhr10%10); // 文字列を作成 lcd_goto(0x4b); lcd_puts(str); // LCD へ表示 6

// Temperature reading SHTTSSeq(); SHTWrite(0x03); // TSシーケンス発行 // measure Temperature コマンド送信 // 変換完了待ち while((sht_port & (1<<bitDATA))) { // A-D 変換完了を待つ bdat_h = SHTRead(0); bdat_l = SHTRead(0); bdat_crc = SHTRead(1); // read high byte(ack) // read low byte(ack) // read CRC(NOACK) ADValTmp = ((int)bdat_h << 8) bdat_l; // 16ビットに合成 wdat = CalcTMP10() ; sprintf(str,"%d.%d C",wdat/10,wdat%10); // 文字列を作成 lcd_goto(0xa); lcd_puts(str); // LCD へ表示 // Serial output printf("date:%c%c/%c%c/%c%c:%c%c:%c%c#",(month>>4)&0x0f 0x30,month&0x0F 0x30,(day>>4)&0x0F 0x30,day&0x0F 0x30,(hour>>4)&0x0F 0x30,hour& 0x0F 0x30,(minute>>4)&0x0F 0x30,minute&0x0F 0x30,(second>>4)&0x0F 0x30,second& 0x0F 0x30); if(wdat>0) printf("rt=%d.%ddeg",wdat/10,wdat%10); else{ wdat=-wdat; printf("rt=-%d.%d%%",wdat/10,wdat%10); printf("rh=%d.%d%%\n\r",valhr10/10,valhr10%10); Heart_beat ^= 1; // Toggle LED // INT release GIE=1; INTE=1; * RTCへデータ1 文字出力 void rtc_write(unsigned char reg_no, unsigned char data){ i2c_writeto(rtc8583); // RTCアドレスをWRITE MODE で OPEN 7

i2c_write(reg_no); i2c_write(data); i2c_stop(); * RTCからデータ1 文字取得 char rtc_read(unsigned char reg_no){ char data; i2c_writeto(rtc8583); i2c_putbyte(reg_no); i2c_readfrom(rtc8583); data=i2c_read(); i2c_stop(); return data; // register select // DATA バイトを送る // stop コンディション // RTCアドレスをREAD MODE で OPEN // register select // RTCアドレスをREAD MODE で REOPEN // DATA バイトを取得する // stop コンディション * LCD へ BCD データ 2 文字表示 void lcd_hex(unsigned char bcd){ lcd_putch(((bcd>>4)&0x0f) 0x30); lcd_putch((bcd&0x0f) 0x30); * Bynary to 2*BCD unsigned char btobc(unsigned char b2){ unsigned char b3; b3=((b2/10)&0x0f)<<4 (b2%10)&0xf ; return (b3); * 2*BCD to Binary unsigned char bctob(unsigned char b1){ unsigned char b0; b0=(b1&0xf) + ((b1>>4)&0x0f)*10; return (b0); * weekday 数字から文字へ変換 LCD 表示 8

void lcd_wkd(unsigned char wkday){ switch(wkday){ case 0: lcd_puts("sun"); case 1: lcd_puts("mon"); case 2: lcd_puts("tue"); case 3: lcd_puts("wed"); case 4: lcd_puts("thu"); case 5: lcd_puts("fri"); case 6: lcd_puts("sat"); default:lcd_puts("bad"); * RTCへデータ列書き込み void rtc_writestr(void){ rtc_write(ctrl,0x80); // Stop day = (day&0x3f) (( bctob(year)&0x3)<<6); // Stacking year on day month = month (weekday<<5);// Stacking weekday on month rtc_write(month,month); // rtc_write(day,day); // rtc_write(hour,hour); // rtc_write(minute,minute); // rtc_write(second,second); // rtc_write(ctrl,0x00); // Start * RTC からデータ WORK へ取り込み void rtc_readstr(void){ rtc_write(ctrl,0x80); month=rtc_read(month); day=rtc_read(day); hour=rtc_read(hour); minute=rtc_read(minute); // Stop // w2w1w0m10 m4m2m1m0 // y1y0d11d10 d4d2d1d0 // 24_0_h11h10 h4h2h1h0 // m14m12m11m10 m4m2m1m0 9

second=rtc_read(second); // s14s12s11s10 s4s2s1s0 weekday=(month&0xe0)>>5; // if(((((rtc_read(day)>>6))&0x3)==0)&((day&0x3f)==1)&((month&0x1f)==1)&(hour== 0)&(minute==0)&(second==0)) {year=btobc((bctob(year)&0xfc)+4)+(rtc_read(day)>>6); // if year count up else {year=btobc((bctob(year)&0xfc)+(rtc_read(day)>>6)); // lower 2 year value rtc_write(ctrl,0x00); // Start day=day&0x3f; // strip year data for INC/DEC month=month&0x1f; // strip week data for INC/DEC * RTC データを LCD へ書き込み void rtc_disp(void){ lcd_goto(0x00); // 1st line lcd_hex(year); // **/**/** lcd_putch(0x2f); lcd_hex(month); lcd_putch(0x2f); lcd_hex(day); lcd_putch(0x20); lcd_goto(0x40); // 2nd line lcd_hex(hour); lcd_putch(0x3a); lcd_hex(minute); lcd_putch(0x3a); lcd_hex(second); lcd_wkd(weekday); // data increment and MAX check void data_inc(unsigned char set_pos ){ unsigned char bynary; bynary=(rtc_data[set_pos][0]&0xf0)/16*10+(rtc_data[set_pos][0]&0x0f); bynary++; RTC_DATA[set_pos][0]=btobc(bynary); 10

if(rtc_data[set_pos][0]>(rtc_data[set_pos][1])){ RTC_DATA[set_pos][0]=RTC_DATA[set_pos][2]; // data decrement and 0 check void data_dec(unsigned char set_pos){ unsigned char bynary; if(rtc_data[set_pos][0]==rtc_data[set_pos][2]){ RTC_DATA[set_pos][0]=RTC_DATA[set_pos][1]+1; bynary=(rtc_data[set_pos][0]&0xf0)/16*10+(rtc_data[set_pos][0]&0x0f); bynary--; RTC_DATA[set_pos][0]=btobc(bynary); ******** * MSSP initialize ********* void mssp_init(void){ /* SSP1CON1 REGISTERS */ SSP1CON1bits.SSPEN = 1; //Enables Serial Port Mode SSP1CON1bits.SSPM3 = 1; ///////// SSP1CON1bits.SSPM2 = 0; //I2C Master Mode SSP1CON1bits.SSPM1 = 0; // clock= Fosc/(4*(SSP1ADD+1)) SSP1CON1bits.SSPM0 = 0; //////// /* SSPCON2 REGISTERS */ SSP1CON2 = 0x00; /* SSPCON3 REGISTERS */ SSP1CON3 = 0x00; /* SSP1STAT REGISTERS */ SSP1STATbits.SMP = 1; //SPI MASTER MODE SSP1STATbits.CKE = 0; //SMBus Specific Inputs Enabled //SSP1ADD = 0x19; //~75kHz //SSP1ADD = 0x13; //~100kHz //SSP1ADD = 0x07; //~400kHz SSP1ADD = 0x50; // atandard serial I/O void putch(unsigned char c ){ 11

put_uart(c); return; // Interrupt routine void interrupt clk1hz(void){ GIE=0; if ( INTF ) { INTF = 0; clk1hzint=1; // interrupt on change // 1Hz int flag on 12