FRMD KL25Z <=i2c=> NXP PCF8563 (RTC) FRMD KL25Z SPI=> MCP23S17 => (GLCD) T6963C FRMD KL25Z Tsi => 3 button : <--> <enter> <++> FRMD KL25Z => Bip()
Fork of RTC8564NB_Clock by
Revision 2:c271f83a69e4, committed 2014-05-14
- Comitter:
- szjenter
- Date:
- Wed May 14 04:46:52 2014 +0000
- Parent:
- 1:7c1d3790f08d
- Commit message:
- FRMD KL25Z <=i2c=> NXP PCF8563 (RTC); FRMD KL25Z SPI=> MCP23S17 => (GLCD T6963C); FRMD KL25Z Tsi => 3 button : <--> <enter> <++>; FRMD KL25Z => Bip()
Changed in this revision
diff -r 7c1d3790f08d -r c271f83a69e4 EthernetNetIf.lib --- a/EthernetNetIf.lib Wed Apr 27 11:03:21 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 7c1d3790f08d -r c271f83a69e4 GLCD_spi.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GLCD_spi.h Wed May 14 04:46:52 2014 +0000 @@ -0,0 +1,446 @@ +#ifndef GLCDSPI_H +#define GLCDSPI_H + +/*** GLCD_spi.h*** +* Új változat char* int_string(int) +* MCP23S17 - Microchip MCP23S17 16-bit Port Extender using SPI +* Copyright (c) 2010 Gert van der Knokke +*/ +#include "mbed.h" + +// for 21 characters on a row (6x8 font) +#define LCDFONTSEL 0xFF +// for 16 characters on a row (8x8 font) +// #define LCDFONTSEL 0xDF + +#define IODIRA 0x00 +#define IODIRB 0x01 +#define IPOLA 0x02 +#define IPOLB 0x03 +#define GPINTENA 0x04 +#define GPINTENB 0x05 +#define DEFVALA 0x06 +#define DEFVALB 0x07 +#define INTCONA 0x08 +#define INTCONB 0x09 +#define IOCONA 0x0A +#define IOCONB 0x0B +#define GPPUA 0x0C +#define GPPUB 0x0D +#define INTFA 0x0E +#define INTFB 0x0F +#define INTCAPA 0x10 +#define INTCAPB 0x11 +#define GPIOA 0x12 +#define GPIOB 0x13 +#define OLATA 0x14 +#define OLATB 0x15 + +// LCD pin connections/bit numbers +#define LCD_HALT 0x80 +#define LCD_FS 0x20 +#define LCD_RST 0x10 +#define LCD_CD 0x08 +#define LCD_CE 0x04 +#define LCD_RD 0x02 +#define LCD_WR 0x01 + +// T6963C OPCODES +#define TXHOME 0x40 // SET TXT HOME ADDRESS +#define TXAREA 0x41 // SET TXT AREA +#define GRHOME 0x42 // SET GRAPHIC HOME ADDRESS +#define GRAREA 0x43 // SET GRAPHIC AREA +#define OFFSET 0x22 // SET OFFSET ADDRESS +#define ADPSET 0x24 // SET ADDRESS POINTER +#define AWRON 0xB0 // SET AUTO WRITE MODE +#define AWROFF 0xB2 // RESET AUTO WRITE MODE + + +/* This file contains definitions for all of the commands in a t6963. */ +/********************************************************************/ +/* Register set */ +#define CPS 0x21 //Cursor pointer set +#define ORS 0x22 //Offset register set +#define APS 0x24 //Address pointer set +#define THAS 0x40 //Text home address set +#define TAS 0x41 //Text area set +#define GHAS 0x42 //Graphic home address set +#define GAS 0x43 //Graphic area set +#define OM 0x80 //OR mode +#define EM 0x81 //EXOR mode +#define AM 0x83 //AND mode +#define TAM 0x84 //TEXT ATTRIBUTE mode +#define DOF 0x90 //Display OFF +#define CONBOF 0x92 //Cursor ON, Blink OFF +#define CONBON 0x93 //Cursor ON, Blink ON +#define TONGOF 0x94 //Text ON, Graphic OFF +#define TOFGON 0x98 //Text OFF, Graphic ON +#define TONGON 0x9C //Text ON, Graphic ON +#define LC1 0xA0 //1 Line cursor +#define LC2 0xA1 //2 Line cursor +#define LC3 0xA2 //3 Line cursor +#define LC4 0xA3 //4 Line cursor +#define LC5 0xA4 //5 Line cursor +#define LC6 0xA5 //6 Line cursor +#define LC7 0xA6 //7 Line cursor +#define LC8 0xA7 //8 Line cursor +#define DAWS 0xB0 //Data auto write set +#define DARS 0xB1 //Data auto read set +#define AR 0xB2 //Auto reset +#define DWAAI 0xC0 //Data write and ADP increment +#define DRAAI 0xC1 //Data read and ADP increment +#define DWAAD 0xC2 //Data write and ADP decrement +#define DRAAD 0xC3 //Data read and ADP decrement +#define DWAAN 0xC4 //Data write and ADP nonvariable +#define DRAAN 0xC5 //Data read and ADP nonvariable +#define SP 0xE0 //Screen PEEK +#define SC 0xE8 //Screen COPY +#define BR 0xF0 //Bit RESET +#define BS 0xF8 //Bit SET +//add 3 bit data to these +//commands to select bit + +// for 21 characters on a row (6x8 font) +#define LCDFONTSEL 0xFF +// for 16 characters on a row (8x8 font) +// #define LCDFONTSEL 0xDF + +// lcd dimensions in pixels +#define LCD_XWIDTH 128 +#define LCD_YHEIGHT 64 + +#if LCDFONTSEL == 0xFF +// lcd dimensions in characters +#define LCD_WIDTH 22 +#define LCD_HEIGHT 16 +#define PIXELWIDTH 6 +#else +#define LCD_WIDTH 16 +#define LCD_HEIGHT 16 +#define PIXELWIDTH 8 +#endif + +#define TEXT_STARTADDRESS 0x0000 +#define GRAPHIC_STARTADDRESS 0x1000 + + +#define CENTERX 50 +#define CENTERY 32 +#define INNER_RADIUS 20 +#define OUTER_RADIUS 25 +#define CENTER_CIRCLE 5 + +extern char d[14]={0}; // inttochar() visszaadott érték string-je + +//DigitalOut K_LED(LED1), P_LED(LED3), Z_LED(LED2); +SPI spi(PTC6, PTC7, PTC5); // mosi, miso, sclk +DigitalOut cs2(PTC10); //CS1=PTC11; CS2=PTC10; CS3=PTC4 Hardware CS a panelon +//---------------------------------------------------- +void SPI_init() +{ + // set SPI to full speed (10 MHz mode) + spi.format(8,0); + spi.frequency(10000000); + //spi.frequency(10000); +} +//---------------------------------------------------- + +void lcd_data(unsigned char d) // write 8 bits lcd data +{ + cs2=0; + spi.write(0x40); + spi.write(GPIOB); // select GPIOB + spi.write(d); // set data byte + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL-LCD_CE-LCD_CD); + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL - LCD_WR - LCD_CE - LCD_CD); + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL - LCD_CD); + cs2=1; + +} +//---------------------------------------------------- + +void lcd_command(unsigned char c) // write 8 bits lcd command +{ + cs2=0; + spi.write(0x40); + spi.write(GPIOB); // select GPIOB + spi.write(c); // set data byte + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL-LCD_CE); + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL - LCD_WR - LCD_CE); + cs2=1; + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA + spi.write(LCDFONTSEL); + cs2=1; +} +//---------------------------------------------------- +void lcd_init() //Grafikus LCD initializálása +{ + cs2=0; + spi.write(0x40); + spi.write(IODIRA); // select IODIRA at start + spi.write(0x00); // IODIRA all outputs + spi.write(0x00); // IODIRB all outputs + cs2=1; + wait(0.1); + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA at start + spi.write(LCDFONTSEL-LCD_RST); // activate reset + spi.write(0x00); // all B outputs 0 + cs2=1; + wait(0.1); + + cs2=0; + spi.write(0x40); + spi.write(GPIOA); // select GPIOA at start + spi.write(LCDFONTSEL); // deactivate reset + cs2=1; + wait(0.1); + + // set text home address at 0x0000 + lcd_data(TEXT_STARTADDRESS%0x100); + lcd_data(TEXT_STARTADDRESS/0x100); + lcd_command(TXHOME); + + // set graphic home address at 0x1000 + lcd_data(GRAPHIC_STARTADDRESS%0x100); + lcd_data(GRAPHIC_STARTADDRESS/0x100); + lcd_command(GRHOME); + + // set text area + lcd_data(LCD_WIDTH); + lcd_data(0x00); + lcd_command(TXAREA); + + // set graphic area + lcd_data(LCD_WIDTH); + lcd_data(0x00); + lcd_command(GRAREA); + + // mode set (internal character generation mode) + lcd_command(0x80); + + // set offset register + lcd_data(0x02); + lcd_data(0x00); + lcd_command(OFFSET); + + // display mode (text on graphics on cursor off) + lcd_command(0x90+0x08+0x04); + +} +//------------------------------------------------- + +//------------------------------------------------------ +char* int_string(double da){ // elő nullák nélküli kiíratás + + int b,c,dx,i; //b=adott helyiértéken a számjegy, c=0 akkor elő nulla; dx= az elő nullák nélküli helyiérték száma + char* f; // egy karakter tipusú változó pointere + c=0; + dx=0; + for(i=0;i<15;i++){d[i]=char(0x00);} + //teszt adat: + //da=123456; + b=int(da/100000000); // 9. helyiérték + if(b>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*100000000; // 8. helyiérték + b=int(da/10000000); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*10000000; // 7. helyiérték + b=int(da/1000000); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*1000000; // 6. helyiérték + b=int(da/100000); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*100000; // 5. helyiérték + b=int(da/10000); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*10000; // 4. helyiérték + b=int(da/1000); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*1000; // 3. helyiérték + b=int(da/100); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*100; // 2. helyiérték + b=int(da/10); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + da = da - b*10; // 1. helyiérték + b=int(da); + if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} + // visszatérési érték: d[] string + f = d; // f tartalmazza a d char tömb pointerét + return f; +} + + + +//------------------------------------------------------ +void lcd_string(char y,char x,char *s) // put a text string at position x,y (character row,column) +{ + int adr; + adr=TEXT_STARTADDRESS+x+y*LCD_WIDTH; // 0x0000 + x + y + 22 + lcd_data(adr%0x100); // % maradék képzés jele + lcd_data(adr/0x100); + lcd_command(ADPSET); + lcd_command(AWRON); + while (s[0]){ + // convert from ascii to t6963 + lcd_data(s[0]-32); + s++; + } + lcd_command(AWROFF); +} +//---------------------------------------------------- +void lcd_cls() // clear lcd display memory (8k) +{ + int a; + lcd_data(0x00); + lcd_data(0x00); + lcd_command(ADPSET); + lcd_command(AWRON); + for (a=0; a<8192; a++) lcd_data(0); + lcd_command(AWROFF); +} +//---------------------------------------------------- +void lcd_plot(char x,char y,char color) // set or reset a pixel on the display on position x,y with color 0 or 1 +{ + int adr; + adr = GRAPHIC_STARTADDRESS + ((LCD_WIDTH) * y) + (x/PIXELWIDTH); // calculate offset + lcd_data(adr%0x100); // set low byte + lcd_data(adr/0x100); // set high byte + lcd_command(ADPSET); // set address pointer + if (color) lcd_command(BS + ((PIXELWIDTH-1)-(x%PIXELWIDTH))); // use bit set mode + else lcd_command(BR + ((PIXELWIDTH-1)-(x%PIXELWIDTH))); // use bit reset mode +} +//---------------------------------------------------- + +void lcd_line(int x0, int y0, int x1, int y1,char color) // Bresenham line routine 0-128 x 0-64 color= char(1) +{ // color 1, 0 + char steep=1; + int i,dx,dy,e; + signed char sx,sy; + + dx = abs(x1-x0); + sx = ((x1 - x0) >0) ? 1 : -1; + dy=abs(y1-y0); + sy = ((y1 - y0) >0) ? 1 : -1; + + if (dy > dx) + { + steep=0; + // swap X0 and Y0 + x0=x0 ^ y0; + y0=x0 ^ y0; + x0=x0 ^ y0; + + // swap DX and DY + dx=dx ^ dy; + dy=dx ^ dy; + dx=dx ^ dy; + + // swap SX and SY + sx=sx ^ sy; + sy=sx ^ sy; + sx=sx ^ sy; + } + + e = (dy << 1) - dx; + + for (i=0; i<=dx; i++) + { + if (steep) + { + lcd_plot(x0,y0,color); + } + else + { + lcd_plot(y0,x0,color); + } + while (e >= 0) + { + y0 += sy; + e -= (dx << 1); + } + x0 += sx; + e += (dy << 1); + } + } +//---------------------------------------------------- + +// kör kirajzolása +void lcd_circle(int x0,int y0, int radius, char color) // Bresenham circle routine +{ + int i; + float cx =1.3; // kör rajzolás LCD torzítás kompenzálása + i=0; + //char sa[3]; + int f = 1 - radius; + int dx = 1; + int dy = -2 * radius; + int x = 0; + int y = radius; + //float cx =1.3; + lcd_plot(x0 * cx, y0 + radius,color); + lcd_plot(x0 * cx, y0 - radius,color); + lcd_plot((x0 + radius) * cx, y0,color); + lcd_plot((x0 - radius) * cx, y0,color); + + while(x < y){ + i++; + if(f >= 0) + { + y--; + dy += 2; + f += dy; + } + x++; + dx += 2; + f += dx; + lcd_plot((x0 + x) * cx, y0 + y,color); + //a=(x0+x)*cx; + //glcd_inttochar(a); + //lcd_string(0,0,d); + //a= y0 + y; + //glcd_inttochar(a); + //lcd_string(12,0,d); + lcd_plot((x0 - x) * cx, y0 + y,color); + lcd_plot((x0 + x) * cx, y0 - y,color); + lcd_plot((x0 - x) * cx, y0 - y,color); + lcd_plot((x0 + y) * cx, y0 + x,color); + lcd_plot((x0 - y) * cx, y0 + x,color); + lcd_plot((x0 + y) * cx, y0 - x,color); + lcd_plot((x0 - y) * cx, y0 - x,color); + //wait(.2); + } +} + +#endif \ No newline at end of file
diff -r 7c1d3790f08d -r c271f83a69e4 NTPClient.lib --- a/NTPClient.lib Wed Apr 27 11:03:21 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
diff -r 7c1d3790f08d -r c271f83a69e4 RTC.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RTC.h Wed May 14 04:46:52 2014 +0000 @@ -0,0 +1,246 @@ +#ifndef RTC_H +#define RTC_H + +#include "mbed.h" +#include "GLCD_spi.h" +#include "TouchMenu.h" + +#define RTC8563 0xA2 + +#define CONTROL1 0x00 +#define CONTROL2 0x01 +#define SECONDS 0x02 +#define MINUTES 0x03 +#define HOURS 0x04 +#define DAYS 0x05 +#define WEEKDAYS 0x06 +#define MONTHS 0x07 +#define YEARS 0x08 +#define MINUTE_ALARM 0x09 +#define HOUR_ALARM 0x0A +#define DAY_ALARM 0x0B +#define WEEKDAY_ALARM 0x0C +#define CLOCKOUT_FREQ 0x0D +#define TIMER_CINTROL 0x0E +#define TIMER 0x0F +#define _READ 0x01 + +I2C i2c(PTE0, PTE1); //SDA, SCL +TouchRun TchR2; +DigitalOut K_LED(LED1), P_LED(LED3), Z_LED(LED2); + + +char year, month, day, week, hour, minute, sec; +int iyear, imonth, iday, iweek, ihour, iminute, isec; +char ntp_year[3], ntp_month[3], ntp_day[3], ntp_week[4]; +char ntp_hour[3], ntp_minute[3], ntp_sec[3]; +char week_val; + +char week_chr[7][4] = {"Vas","Het","Ked","Sze","Csu","Pen","Szo"}; +//------------------------------------------------------------------- +void rtc_write(char address, char value){ + i2c.start(); + i2c.write(RTC8563); + i2c.write(address); + i2c.write(value); + i2c.stop(); +} +//------------------------------------------------------------------- +char rtc_read(char address){ + char value; + i2c.start(); + i2c.write(RTC8563); + i2c.write(address); + i2c.start(); + i2c.write(RTC8563 | _READ); + value = i2c.read(0); + i2c.stop(); + + return value; +} +//------------------------------------------------------------------- +void time_just(){ + char _min, _hour; + //test_led = !test_led; + _min = rtc_read(MINUTES); + if (_min >= 0x30) { + _hour = rtc_read(HOURS); + if (_hour == 0x23) + _hour = 0x00; + else if ((_hour & 0x0F) == 0x09) + _hour = (_hour & 0xF0) + 0x10; + else + _hour = _hour + 0x01; + rtc_write(HOURS, _hour); + } + rtc_write(MINUTES, 0x00); + rtc_write(SECONDS, 0x00); +} +//------------------------------------------------------------------ +void rtc_reset(){ + //just_button.rise(&time_just); + + lcd_cls(); + lcd_string(2,1,"RTC8563 CLOCK RESET" ); + wait(1); + + rtc_write(CONTROL1, 0x20); //stop + rtc_write(CONTROL2, 0x00); + rtc_write(YEARS, 0x36); //((ntp_year[0]-0x30)<<4)+(ntp_year[1]-0x30)); + rtc_write(MONTHS,0x02); //((ntp_month[0]-0x30)<<4)+(ntp_month[1]-0x30)); + rtc_write(DAYS, 0x03); //((ntp_day[0]-0x30)<<4)+(ntp_day[1]-0x30)); + rtc_write(HOURS, 0x04); //((ntp_hour[0]-0x30)<<4)+(ntp_hour[1]-0x30)); + rtc_write(MINUTES,0x05); //((ntp_minute[0]-0x30)<<4)+(ntp_minute[1]-0x30)); + rtc_write(SECONDS,0x00); //((ntp_sec[0]-0x30)<<4)+(ntp_sec[1]-0x30)); + rtc_write(WEEKDAYS, week_val); + rtc_write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz + rtc_write(TIMER_CINTROL, 0x00); + rtc_write(CONTROL1, 0x00); //start +} +//------------------------------------------------------------------ +void rtc_data_read(){ + i2c.start(); + i2c.write(0xA2); + i2c.write(0x02); + i2c.stop(); + i2c.start(); + i2c.write(0xA3); + sec = i2c.read(SECONDS) & 0x7F; + minute = i2c.read(MINUTES) & 0x7F; + hour = i2c.read(HOURS) & 0x3F; + day = i2c.read(DAYS) & 0x3F; + week = i2c.read(WEEKDAYS) & 0x07; + month = i2c.read(MONTHS) & 0x1F; + year = i2c.read(YEARS); + i2c.stop(); + + + //lcd.locate(0,0); + sprintf(buffer,"%c%c/%c%c/%c%c %s", + ((year >> 4) & 0x0F) + 0x30, (year & 0x0F) + 0x30, //int((year >> 4)& 0x0F)*10 + int(year & 0x0F), + ((month >> 4) & 0x01) + 0x30, (month & 0x0F) + 0x30, + ((day >> 4) & 0x03)+ 0x30, (day & 0x0F) + 0x30, + week_chr[week & 0x07]); + lcd_string(0,0,buffer); + //lcd.locate(0,1); + sprintf(buffer,"%c%c:%c%c:%c%c", + ((hour >> 4) & 0x03) + 0x30, (hour & 0x0F) + 0x30, + (minute >> 4) + 0x30, (minute & 0x0F) + 0x30, + (sec >> 4) + 0x30, (sec & 0x0F) + 0x30 ); + lcd_string(0,13,buffer); +} +//-------------------------------------------------------------- +void rtc_data_set(){ + + rtc_data_read(); + //-------------------------------------------------- + year = (int)((((year >> 4)& 0x0F)*10) + (year & 0x0F)); + + sprintf(buffer,"Year: "); + year = SetBox(year, 0, 99); + Bip(1,1); + + sprintf(buffer,"%d",year); + if(year > 9){ // két helyiértékesetén + year = buffer[0] & 0x0F; + year = (year<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + year = buffer[0] & 0x0F; + } + // a visszaalakítás azonos mint a beolvasásnál + //sprintf(buffer,"Year:%c%c", ((year >> 4) & 0x0F) + 0x30, (year & 0x0F) + 0x30); + //lcd_string(5,0,buffer); + //-------------------------------------------------- + month = (int)((((month >> 4)& 0x01)*10) + (month & 0x0F)); + + sprintf(buffer,"Month: "); + month = SetBox(month, 1, 12); + Bip(1,1); + + sprintf(buffer,"%d",month); + if(month > 9){ // két helyiértékesetén + month = buffer[0] & 0x0F; + month = (month<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + month = buffer[0] & 0x0F; + } + //-------------------------------------------------- + day = (int)((((day >> 4)& 0x03)*10) + (day & 0x0F)); + + sprintf(buffer,"Day: "); + day = SetBox(day, 1, 31); + Bip(1,1); + + sprintf(buffer,"%d",day); + if(day > 9){ // két helyiértékesetén + day = buffer[0] & 0x0F; + day = (day<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + day = buffer[0] & 0x0F; + } + + //-------------------------------------------------- + week = (int)((((week >> 4)& 0x03)*10) + (week & 0x0F)); + + sprintf(buffer,"Week: "); + week = SetBox(week + 1, 1, 7); + Bip(1,1); + + sprintf(buffer,"%d",week - 1); + if(week > 9){ // két helyiértékesetén + week = buffer[0] & 0x0F; + week = (week<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + week = buffer[0] & 0x0F; + } + + //-------------------------------------------------- + hour = (int)((((hour >> 4)& 0x03)*10) + (hour & 0x0F)); + + sprintf(buffer,"Hour: "); + hour = SetBox(hour, 0, 23); + Bip(1,1); + + sprintf(buffer,"%d",hour); + if(hour > 9){ // két helyiértékesetén + hour = buffer[0] & 0x0F; + hour = (hour<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + hour = buffer[0] & 0x0F; + } + + //-------------------------------------------------- + minute = (int)((((minute >> 4)& 0x07)*10) + (minute & 0x0F)); + + sprintf(buffer,"Minute: "); + minute = SetBox(minute, 0, 23); + Bip(1,1); + + sprintf(buffer,"%d",minute); + if(minute > 9){ // két helyiértékesetén + minute = buffer[0] & 0x0F; + minute = (minute<<4) + (buffer[1] & 0x0F); + }else{ // egy helyiérték esetén + minute = buffer[0] & 0x0F; + } + //------------------------------------------------- + + rtc_write(CONTROL1, 0x20); //stop + rtc_write(CONTROL2, 0x00); + rtc_write(YEARS, year); //((ntp_year[0]-0x30)<<4)+(ntp_year[1]-0x30)); + rtc_write(MONTHS,month); + rtc_write(DAYS, day); + rtc_write(WEEKDAYS,week); + rtc_write(HOURS, hour); + rtc_write(MINUTES, minute); + rtc_write(SECONDS,0x00); + rtc_write(CONTROL1, 0x00); //start +} + + + + + + + +#endif \ No newline at end of file
diff -r 7c1d3790f08d -r c271f83a69e4 TSI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Wed May 14 04:46:52 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/emilmont/code/TSI/#507b1f67804b
diff -r 7c1d3790f08d -r c271f83a69e4 TextLCD.lib --- a/TextLCD.lib Wed Apr 27 11:03:21 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 7c1d3790f08d -r c271f83a69e4 TouchMenu.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TouchMenu.h Wed May 14 04:46:52 2014 +0000 @@ -0,0 +1,303 @@ +#ifndef TOUCHMENU_H +#define TOUCHMENU_H +#include "bip.h" +#include "TSISensor.h" +#include "mbed.h" +#include "GLCD_spi.h" + +//******************************************* +/* TouchRun osztály +// Példányosítás: TouchRun TchR; +// +*/ +class TouchRun{ +public: + TouchRun(); // Konstruktor + //~TouchRun(); // Destructor + int touch_run(void); +private: + void kurzor(void); + void kurzor_torles(void); + void kep(void); + void akcio(void); + + char buffer[22]; + int touch_status; + int touch_value; + int T_value; + int a; + TSISensor tsi; + Timer touch_timer; +}; +//******************************************* + +//** Fügvény definició ********************** + + +//------------------------------------------- +//------------------------------------------- +void TouchRun::kurzor(){ + lcd_string(touch_value+1,1,">>"); +} + +//------------------------------------------- +void TouchRun::kurzor_torles(){ + lcd_string(2,0," "); + lcd_string(3,0," "); + lcd_string(4,0," "); + lcd_string(5,0," "); + lcd_string(6,0," "); + +} +//------------------------------------------- +void TouchRun::akcio(){ + int touch=0; + touch = int(tsi.readPercentage()*100); // vissza adott érték: + if(touch==0){touch_value=0; return;} + if(touch>0 & touch<33) {touch_value=1; return;} // [<] z_villan(); + if(touch>32 & touch<66) {touch_value=2; return;} // [ent] z_villan(); + if(touch>65 & touch<101){touch_value=3; return;} // [>] z_villan(); + return; + +} +//------------------------------------------- +void TouchRun::kep(){ + //lcd_cls(); + lcd_string(7,0,"<--> <Ent> <++> "); +} +//------------------------------------------- +int TouchRun::touch_run(){ // Touch állapotgép + //DigitalOut K_LED(LED3); + + switch(touch_status){ + case 0: // állókép kiírása + //K_LED = 1; + kep(); + T_value=1; + touch_status++; + return 0; + case 1: // akció??? + akcio(); // Melyik gombot nyomta meg? : touch_value = 0 semmi, =1 [<], =2 [ENter], =3 [>] + if(touch_value>0){ // Ha volt akció, tovább lép + Bip(2,1); + touch_status++; + } + sprintf(buffer,">%d<",touch_value); + lcd_string(7,18,buffer); + return(touch_value); + case 2: // akció volt + //kurzor(); + //K_LED = 0; + + touch_timer.reset(); //késleltet + touch_timer.start(); + touch_status++; + return 0; + case 3: // timer túl csordult??? + a= touch_timer.read_ms(); + if(a > int(300)){ + touch_timer.stop(); + + touch_status++; + } + return 0; + case 4: // kúrzor megjelenítése + //kurzor_torles(); + touch_status=1; //touch_status++; + return 0; + } + return 0; +} + + +//******************************************* +TouchRun::TouchRun(){ //Konstruktor + touch_status = 0; + touch_value = 0; + //DigitalOut P_LED(LED1), Z_LED(LED2), K_LED(LED3); + +} +//TouchRun::~TouchRun(){} //Destructor +//******************************************* +//******************************************* + + + + + +//******************************************* +/*TouchMenu +// Meghívás: b = TchM.menu_run(a); //Fő menü +// (a) Meghívás paramétere: megadja melyik menüsort jelenitse meg a kép függvény +// (b) Visszatérési paraméter: megadja melyik sorról nyomott <Enter>-t (touch_value) +// +*/ + + int menu_run(int); + TouchRun TchR1; + + void mstart(int); + int mkurzor(int); + void kurzor_torles(void); + void akcio(void); + + int t_value; + int m_kurzor; + int m_kurzor_old; + char buffer[22]; + int menu_status; + int menu_value; + int M_value; + int mk_value; + TSISensor tsi; + Timer menu_timer; + +//** Fügvény definiciók ********************** +void mstart(int a){ + char menu_chr[10][7][15] = { + {"FRMD KL25Z "," RTC menu "," Acc menu "," MMG menu "," Press menu "," SET menu "," Fo menu ",}, + {"RTC menu "," Date Set "," Time Set "," Alarm Set "," RTC RUN "," "," Fo menu ",}, + {"Acc menu "," Acc 1 "," Acc 2 "," Acc 3 "," Acc RUN "," "," Fo menu ",}, + {"MMG menu "," MMG 1 "," MMG 2 "," MMG 3 "," MMG4 "," "," Fo menu ",}, + {"Press menu "," Press1 "," Press2 "," Press3 "," Press4 "," "," Fo menu ",}, + {"SET menu "," RTC Set "," 6. 2 "," 6. 3 "," 6. 4 "," "," Fo menu ",}, + {"Date Set m."," Year Set "," Month set "," Day set "," Week set "," "," Fo menu ",}, //RTC + {"Time Set m."," Hour Set "," Minute set "," Second set "," "," "," Fo menu ",}, //RTC + {"AlarmSet m."," AHour Set "," AMinute set "," ASecond set "," "," "," Fo menu ",}, //RTC + {"RTC RUN "," Start "," STOP "," "," "," "," Fo menu ",}, //RTC + }; + + //lcd_string(0,5,menu_chr[a][0]); + lcd_string(1,0,menu_chr[a][1]); + lcd_string(2,0,menu_chr[a][2]); + lcd_string(3,0,menu_chr[a][3]); + lcd_string(4,0,menu_chr[a][4]); + lcd_string(5,0,menu_chr[a][5]); + lcd_string(6,0,menu_chr[a][6]); + + lcd_line(0,7,128,7,char(1)); + lcd_line(0,55,128,55,char(1)); + m_kurzor = 1; + m_kurzor_old = 1; + +} +//------------------------------------------- +int mkurzor(int delta){ + m_kurzor = m_kurzor_old + delta; + if(m_kurzor<1){m_kurzor=6;} + if(m_kurzor>6){m_kurzor=1;} + lcd_string(m_kurzor_old,0," "); + lcd_string(m_kurzor,0,"->"); + m_kurzor_old = m_kurzor; + return m_kurzor; +} +//------------------------------------------- +//------------------------------------------- +int menu_run(int a){ + menu_status=0; + while(1){ + switch(menu_status){ + case 0: + mstart(a); + mk_value = mkurzor(0); + menu_status++; + break; + case 1: + t_value = TchR1.touch_run(); + if(t_value>0){ + menu_status++; + } + break; + case 2: + menu_status = 1; + switch(t_value){ + case 1: + mk_value = mkurzor(-1); + break; + case 3: + mk_value = mkurzor(1); + break; + case 2: + sprintf(buffer,"=>%d",mk_value); + lcd_string(6,15,buffer); + return mk_value; + } + break; + } + } +// return 0; +} +//------------------------------------------------ +void SendBox(){ //buffer[12] -ben van a szöveg változó + + + lcd_string(1,2," "); + lcd_string(2,2," "); + lcd_string(3,2," "); + lcd_string(4,2," SendBox "); + lcd_string(5,2," "); + lcd_string(6,2," "); + lcd_string(3,4,buffer); + + lcd_line(18,10,110,10,char(1)); + lcd_line(110,10,110,50,char(1)); + lcd_line(110,50,18,50,char(1)); + lcd_line(18,50,18,10,char(1)); + wait(2); + lcd_line(18,10,110,10,char(0)); + lcd_line(110,10,110,50,char(0)); + lcd_line(110,50,18,50,char(0)); + lcd_line(18,50,18,10,char(0)); + +} +//-------------------------------------------------------- +int SetBox(int value, int min, int max){ ////buffer[12] -ben van a szöveg változó + TouchRun TchR2; + int t_value; + + lcd_string(1,2," "); + lcd_string(2,2," SetBox "); + lcd_string(3,2," "); + lcd_string(4,2," "); + lcd_string(5,2," "); + lcd_string(6,2," "); + lcd_string(4,4,buffer); + sprintf(buffer,"%d", value); + lcd_string(4,9,buffer); + lcd_line(18,10,110,10,char(1)); + lcd_line(110,10,110,50,char(1)); + lcd_line(110,50,18,50,char(1)); + lcd_line(18,50,18,10,char(1)); + while(1){ + t_value = TchR2.touch_run(); + switch(t_value){ + case 0: + break; + case 1: //-- 0-99 között lehet + value--; + if(value<min){value = max;} + break; + case 2: // Ent. + return value; + case 3: //++ 0-99 között lehet + value++; + if(value>max){value = min;} + break; + } + //sprintf(buffer," "); + //lcd_string(4,9,buffer); + sprintf(buffer,"\b\b%d ", value); + lcd_string(4,9,buffer); + + } +} +//---------------------------------------------- +void BoxClear(){ + lcd_line(18,10,110,10,char(0)); + lcd_line(110,10,110,50,char(0)); + lcd_line(110,50,18,50,char(0)); + lcd_line(18,50,18,10,char(0)); + + +} +#endif \ No newline at end of file
diff -r 7c1d3790f08d -r c271f83a69e4 bip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bip.h Wed May 14 04:46:52 2014 +0000 @@ -0,0 +1,25 @@ +#ifndef BIP_H +#define BIP_H +#include "mbed.h" +/* Ez egy 0.1 s hosszú 1 kHz jel alapból, meghívása: Bip(int freq, int time) +// freki = 1 kHz * freq +// idő = 0.1 s * time +// Flehsználja: PTD7 lábat +*/ +DigitalOut bip(PTD7); +Ticker timer; +int v=0; + +void attime(){v=1;} + +void Bip(int freq, int time){ + v=0; + timer.attach(&attime, 0.1*time); + while(1){ + bip = !bip; + wait(0.001/freq); + if(v>0){bip = 0; return;} + } +} + +#endif \ No newline at end of file
diff -r 7c1d3790f08d -r c271f83a69e4 main.cpp --- a/main.cpp Wed Apr 27 11:03:21 2011 +0000 +++ b/main.cpp Wed May 14 04:46:52 2014 +0000 @@ -1,182 +1,45 @@ -/* -This is the clock which used highly quality RTC module RT8564NB. -This module is I2C controllable. At the time of poweron/reset, the start -time received from ntp server. - -Revision History: -Rev. 0.01A 2011/04/26 New -Rev. 0.01B 2011/04/27 Add time justify function, sec LED - */ #include "mbed.h" -#include "TextLCD.h" -#include "EthernetNetIf.h" -#include "NTPClient.h" - -#define RTC8564NB_ADR 0xA2 +#include "GLCD_spi.h" +#include "TouchMenu.h" +#include "RTC.h" -#define CONTROL1 0x00 -#define CONTROL2 0x01 -#define SECONDS 0x02 -#define MINUTES 0x03 -#define HOURS 0x04 -#define DAYS 0x05 -#define WEEKDAYS 0x06 -#define MONTHS 0x07 -#define YEARS 0x08 -#define MINUTE_ALARM 0x09 -#define HOUR_ALARM 0x0A -#define DAY_ALARM 0x0B -#define WEEKDAY_ALARM 0x0C -#define CLOCKOUT_FREQ 0x0D -#define TIMER_CINTROL 0x0E -#define TIMER 0x0F -#define _READ 0x01 -TextLCD lcd(p24, p26, p27, p28, p29, p30); -EthernetNetIf eth; -NTPClient ntp; -I2C i2c(p9, p10); -DigitalOut sec_led(LED1); -DigitalOut test_led(LED2); -InterruptIn just_button(p15); -int offset_JAPAN = 32400; -char year, month, day, week; -char hour, minute, sec; -char ntp_year[3], ntp_month[3], ntp_day[3], ntp_week[4]; -char ntp_hour[3], ntp_minute[3], ntp_sec[3]; -char week_val; - -char week_chr[7][4] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; +//char buffer[12]; +int m_value,b; +//------------------------------------------------- +void Start(){ + SPI_init(); + lcd_init(); -void rtc_write(char address, char value) -{ - i2c.start(); - i2c.write(RTC8564NB_ADR); - i2c.write(address); - i2c.write(value); - i2c.stop(); + K_LED=1; + Z_LED=1; + P_LED=1; + lcd_cls(); + lcd_string(2,6,"RTC Start"); + Bip(2,3); // 1 kHz * freki, 0.1 s * time + //rtc_reset(); + rtc_data_set(); + lcd_cls(); + //a=0; + b=0; } - -char rtc_read(char address) -{ - char value; - i2c.start(); - i2c.write(RTC8564NB_ADR); - i2c.write(address); - i2c.start(); - i2c.write(RTC8564NB_ADR | _READ); - value = i2c.read(0); - i2c.stop(); - - return value; -} - -void time_just() -{ - char _min, _hour; - test_led = !test_led; - _min = rtc_read(MINUTES); - if (_min >= 0x30) { - _hour = rtc_read(HOURS); - if (_hour == 0x23) - _hour = 0x00; - else if ((_hour & 0x0F) == 0x09) - _hour = (_hour & 0xF0) + 0x10; - else - _hour = _hour + 0x01; - rtc_write(HOURS, _hour); - } - rtc_write(MINUTES, 0x00); - rtc_write(SECONDS, 0x00); -} +//------------------------------------------------- int main() { - just_button.rise(&time_just); + Start(); + //rtc_reset(); + while(1){ + rtc_data_read(); + if(sec != b){ + //Bip(1,1); + b=sec; + Z_LED =0; + wait(.1); + Z_LED=1; + } + } + //for(;;){} - lcd.cls(); - lcd.printf("RTC8564NB CLOCK" ); - wait(2.0); - - /* Set up Ethernet */ - lcd.cls(); - lcd.printf("Setting up Eth\n"); - EthernetErr ethErr = eth.setup(); - if (ethErr) { - lcd.cls(); - lcd.printf("Error with Eth\nNum: %d", ethErr); - return -1; - } - - /* Set up NTP */ - lcd.printf("Setting up NTP\n"); - Host server(IpAddr(), 123, "ntp1.jst.mfeed.ad.jp"); - ntp.setTime(server); - - time_t seconds = time(NULL)+offset_JAPAN; - - lcd.cls(); - strftime(ntp_year, 16, "%y", localtime(&seconds)); - strftime(ntp_month, 16, "%m", localtime(&seconds)); - strftime(ntp_day, 16, "%d", localtime(&seconds)); - strftime(ntp_week, 16, "%a", localtime(&seconds)); - strftime(ntp_hour, 16, "%H", localtime(&seconds)); - strftime(ntp_minute, 16, "%M", localtime(&seconds)); - strftime(ntp_sec, 16, "%S", localtime(&seconds)); - - switch (ntp_week[0]){ - case 'S': - switch (ntp_week[1]) { - case 'u': week_val = 0x00; break; - case 'a': week_val = 0x06; break; - } - break; - case 'M': week_val = 0x01; break; - case 'T': - switch (ntp_week[1]) { - case 'u': week_val = 0x02; break; - case 'h': week_val = 0x04; break; - } - break; - case 'W': week_val = 0x03; break; - case 'F': week_val = 0x05; break; - } - - rtc_write(CONTROL1, 0x20); //stop - rtc_write(CONTROL2, 0x00); - rtc_write(YEARS, ((ntp_year[0]-0x30)<<4)+(ntp_year[1]-0x30)); - rtc_write(MONTHS, ((ntp_month[0]-0x30)<<4)+(ntp_month[1]-0x30)); - rtc_write(DAYS, ((ntp_day[0]-0x30)<<4)+(ntp_day[1]-0x30)); - rtc_write(HOURS, ((ntp_hour[0]-0x30)<<4)+(ntp_hour[1]-0x30)); - rtc_write(MINUTES, ((ntp_minute[0]-0x30)<<4)+(ntp_minute[1]-0x30)); - rtc_write(SECONDS, ((ntp_sec[0]-0x30)<<4)+(ntp_sec[1]-0x30)); - rtc_write(WEEKDAYS, week_val); - rtc_write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz - rtc_write(TIMER_CINTROL, 0x00); - rtc_write(CONTROL1, 0x00); //start - - while(1) { - year = rtc_read(YEARS); - month = rtc_read(MONTHS); - day = rtc_read(DAYS); - week = rtc_read(WEEKDAYS); - hour = rtc_read(HOURS); - minute = rtc_read(MINUTES); - sec = rtc_read(SECONDS); - lcd.locate(0,0); - lcd.printf("20%c%c/%c%c/%c%c %s", - ((year >> 4) & 0x03) + 0x30, (year & 0x0F) + 0x30, - ((month >> 4) & 0x01) + 0x30, (month & 0x0F) + 0x30, - ((day >> 4) & 0x03)+ 0x30, (day & 0x0F) + 0x30, - week_chr[week & 0x07]); - lcd.locate(0,1); - lcd.printf("%c%c:%c%c:%c%c", - ((hour >> 4) & 0x03) + 0x30, (hour & 0x0F) + 0x30, - (minute >> 4) + 0x30, (minute & 0x0F) + 0x30, - (sec >> 4) + 0x30, (sec & 0x0F) + 0x30 ); - - sec_led = !sec_led; - wait(0.5); - } }
diff -r 7c1d3790f08d -r c271f83a69e4 mbed.bld --- a/mbed.bld Wed Apr 27 11:03:21 2011 +0000 +++ b/mbed.bld Wed May 14 04:46:52 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912 +http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file