/* ********************************************************************** * File: Hello_uk.c - Rel. 1.1 Compiler: uC/51 V. 1.20.04 * * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * * Hardware: GMM 935 adn GMM 935.11 * * Tel. +39 051 892052 Fax. +39 051 893661 * * http://www.grifo.com http://www.grifo.it * * by Graziano Gaiba 01.02.06 * ********************************************************************** 01/02/06: Hello_uk.C - Rel 1.1 - By Graziano Gaiba Program preloaded im mini modules. Makes the on-board LED blink. Note To avoid problems do not use complex operations on a single source line, especially inside procedures by using their parameters or their local variables. */ /*************** Header, constant, data structure, etc. ********************/ #include "89lpc935.h" #define RCINT 7372800 // Internal RC clock frequency #define QZ11M 11059200 // External crystal clock frequency near unsigned long clk; // CPU clock requency /**************************************************************************** General purpose functions and card hw sections management functions ****************************************************************************/ /* Read the configuration byte UCFG1 in FLASH through procedure IAP of Boot Rom P89LPC935. Return the value read without making any error check. */ unsigned char rd_ucfg1(void) { #asm mov A,#$03 ; Usa comando Misc. Read mov R7,#$00 ; Legge registro UCFG1 lcall $0FF03 ; Chiama procedura IAP ad indirizzo PGM_MTP #endasm } /* Calibrated delay according to the value of global variable clk */ void delay(unsigned int rit) { unsigned int r,rit1ms; if (clk==RCINT) rit1ms=335; // Value for calibrated delay of 1 msec at 7 MHz else rit1ms=500; // Value for calibrated delay of 1 msec at 11 MHz //endif do { for (r=0 ; r0); } /* CPU initialisation */ void init_cpu(void) { EA=0; // Assure interrupt disabled } /**************************************************************************** Main program ****************************************************************************/ void main(void) { unsigned char dr; init_cpu(); // CPU initialisation clk=RCINT; // Setta clock as internal RC interno (can be acquired only later) P0M1=P0M1 | 0x40; // Set P0.6 in mode 3=Open Drain P0M2=P0M2 | 0x40; dr=rd_ucfg1(); // Read clock configuration from FLASH dr=dr & 0x07; // Masl clock configuration bits switch (dr) { case 0x00: clk=QZ11M; // External crystal clock frequency break; case 0x03: clk=RCINT; // Internal RC clock frequency break; } for(;;) { P0_6=0; // Turn on LED delay(200); // Pause for 200 milliseconds P0_6=1; // Turn off LED delay(200); // Pause for 200 milliseconds } }