/***********************************************************************/ /* */ /* FILE :TimeWatch.c */ /* DATE :Sat, Nov 28, 2009 */ /* DESCRIPTION :Main Program */ /* CPU GROUP :Other */ /* */ /* This file is generated by Renesas Project Generator (Ver.4.13). */ /* */ /***********************************************************************/ #include "sfr_r813.h" #define Punkt p0_3 // Punkt bei SEG2 #define BCD1 p1_0 // 74HC4511: A LSB #define BCD2 p1_1 // 74HC4511: B #define BCD3 p1_2 // 74HC4511: C #define BCD4 p1_3 // 74HC4511: D MSB #define EN1 p3_0 // Enable Eingang Segment 1 #define EN2 p3_1 // Enable Eingang Segment 2 #define EN3 p3_2 // Enable Eingang Segment 3 #define EN4 p3_3 // Enable Eingang Segment 4 #define SEG1_sperren p0_4 // Sperren Segment 1 #define SEG2_sperren p0_5 // Sperren Segment 2 #define SEG3_sperren p0_6 // Sperren Segment 3 #define SEG4_sperren p0_7 // Sperren Segment 4 #define TRUE 1 #define FALSE 0 int Stunde_Zehner = 0; int Stunde_Einer = 0; int Minute_Zehner = 0; int Minute_Einer = 0; int Sekunde_Zehner = 0; int Sekunde_Einer = 0; void Clk_20MHz(void); void UART0_init(void); void sendSerial(unsigned char data); unsigned char receiveSerial (void); void delayus (unsigned int micros); void delayms(unsigned int ms); void BCD_Ausgabe (int BCD); void SEG1_Ausgabe(int Wert1); void SEG2_Ausgabe(int Wert2); void SEG3_Ausgabe(int Wert3); void SEG4_Ausgabe(int Wert4); void Anzeige_Test(); void SEG(); void main(void) { Clk_20MHz(); // Auf 20MHz takten prc2 = 1; // Port 1 Write Enabled pd0_3 = 1; //Punkt als Ausgnang prc2 = 1; pd0_4 = 1; // Freigabe als Ausgänge prc2 = 1; pd0_5 = 1; prc2 = 1; pd0_6 = 1; prc2 = 1; pd0_7 = 1; pd1_0 = 1; // BCD als Ausgänge pd1_1 = 1; pd1_2 = 1; pd1_3 = 1; pd3_0 = 1; // Enable als Ausgänge pd3_1 = 1; pd3_2 = 1; pd3_3 = 1; Punkt = FALSE; BCD1 = FALSE; BCD2 = FALSE; BCD3 = FALSE; BCD4 = FALSE; EN1 = TRUE; EN2 = TRUE; EN3 = TRUE; EN4 = TRUE; SEG1_sperren = TRUE; SEG2_sperren = TRUE; SEG3_sperren = TRUE; SEG4_sperren = TRUE; Anzeige_Test(); // Durchlauf aller Segmente 0 bis 9 UART0_init(); // 2. serielle Sendeschnittstelle initialisieren Stunde_Zehner = receiveSerial(); //Stunde_Zehner Stunde_Einer = receiveSerial(); //Stunde_Einer Minute_Zehner = receiveSerial(); //Minute_Zehner Minute_Einer = receiveSerial(); //Minute_Einer Sekunde_Zehner = receiveSerial(); //Sekunde_Zehner Sekunde_Einer = receiveSerial(); //Sekunde_Einer while(1) { SEG1_Ausgabe(Stunde_Zehner); SEG2_Ausgabe(Stunde_Einer); SEG3_Ausgabe(Minute_Zehner); SEG4_Ausgabe(Minute_Einer); } } // Taktfunktion 20MHz void Clk_20MHz (void) { prc0 = 1; /* Protect off */ cm13 = 1; /* Xin Xout */ cm15 = 1; /* XCIN-XCOUT drive capacity select bit : HIGH */ cm05 = 0; /* Xin on */ cm16 = 0; /* Main clock = No division mode */ cm17 = 0; cm06 = 0; /* CM16 and CM17 enable */ asm("nop"); /* Waiting for stable of oscillation */ asm("nop"); asm("nop"); asm("nop"); ocd2 = 0; /* Main clock change */ prc0 = 0; /* Protect on */ } // UART initialisierung void UART0_init(void) { p1 = p1 | 0x10; pd1 = pd1 | 0x10; pd1 = pd1 & 0xdf; u0mr = 0x05; u0c0 = 0x00; u0rrm = 0; u0brg = 130-1; // 9600 Baud bei 20MHz ; re_u0c1 = 1; } // Serielle Funktionen void sendSerial(unsigned char data) { while (ti_u0c1 == 0); u0tbl = data; te_u0c1 = 1; } unsigned char receiveSerial (void) { int a = 0; unsigned char data; unsigned char dummy; while (ir_s0ric == 0); ir_s0ric = 0; data = u0rbl; dummy = u0rbh; re_u0c1 = 1; return data; } void BCD_Ausgabe(int BCD) // BCD Werte übergeben { if(BCD == 0) { BCD1 = 0; BCD2 = 0; BCD3 = 0; BCD4 = 0; } if(BCD == 1) { BCD1 = 1; BCD2 = 0; BCD3 = 0; BCD4 = 0; } if(BCD == 2) { BCD1 = 0; BCD2 = 1; BCD3 = 0; BCD4 = 0; } if(BCD == 3) { BCD1 = 1; BCD2 = 1; BCD3 = 0; BCD4 = 0; } if(BCD == 4) { BCD1 = 0; BCD2 = 0; BCD3 = 1; BCD4 = 0; } if(BCD == 5) { BCD1 = 1; BCD2 = 0; BCD3 = 1; BCD4 = 0; } if(BCD == 6) { BCD1 = 0; BCD2 = 1; BCD3 = 1; BCD4 = 0; } if(BCD == 7) { BCD1 = 1; BCD2 = 1; BCD3 = 1; BCD4 = 0; } if(BCD == 8) { BCD1 = 0; BCD2 = 0; BCD3 = 0; BCD4 = 1; } if(BCD == 9) { BCD1 = 1; BCD2 = 0; BCD3 = 0; BCD4 = 1; } } void SEG1_Ausgabe(int Wert1) // Segment 1 Ausgabefunktion { SEG1_sperren = FALSE; // Sperre SEG1 aufheben BCD_Ausgabe(Wert1); // BCD Wert ausgeben SEG1_sperren = TRUE; // Sperre SEG1 aktivieren } void SEG2_Ausgabe(int Wert2) { SEG2_sperren = FALSE; BCD_Ausgabe(Wert2); SEG2_sperren = TRUE; } void SEG3_Ausgabe(int Wert3) { SEG3_sperren = FALSE; BCD_Ausgabe(Wert3); SEG3_sperren = TRUE; } void SEG4_Ausgabe(int Wert4) { SEG4_sperren = FALSE; BCD_Ausgabe(Wert4); SEG4_sperren = TRUE; } //Pause Funktionen void delayus (unsigned int micros) { unsigned int i; for (i = 0; i < micros; i++) { asm("nop"); } } void delayms (unsigned int ms) { unsigned int i; for (i = 0; i < ms; i++) { delayus(1000); } } void Anzeige_Test() // Testfunktion, 0 bis 9 auf allen Segmenten { SEG1_sperren = FALSE; SEG2_sperren = FALSE; SEG3_sperren = FALSE; SEG4_sperren = FALSE, BCD_Ausgabe(0); delayms(100); BCD_Ausgabe(1); delayms(100); BCD_Ausgabe(2); delayms(100); BCD_Ausgabe(3); delayms(100); BCD_Ausgabe(4); delayms(100); BCD_Ausgabe(5); delayms(100); BCD_Ausgabe(6); delayms(100); BCD_Ausgabe(7); delayms(100); BCD_Ausgabe(8); delayms(100); BCD_Ausgabe(9); delayms(100); BCD_Ausgabe(0); SEG1_sperren = TRUE; SEG2_sperren = TRUE; SEG3_sperren = TRUE; SEG4_sperren = TRUE; }