C51 COMPILER V7.05 F12X_INIT_1 02/28/2006 13:19:24 PAGE 1 C51 COMPILER V7.05, COMPILATION OF MODULE F12X_INIT_1 OBJECT MODULE PLACED IN F12x_INIT_1.OBJ COMPILER INVOKED BY: F:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F12x_INIT_1.c DB OE stmt level source *** WARNING C500 IN LINE 1 OF F12X_INIT_1.C: MISSING DEVICE (SECURITY KEY NOT FOUND) 1 //----------------------------------------------------------------------------- 2 // F12x_INIT_1.c 3 //----------------------------------------------------------------------------- 4 // Copyright 2002 Cygnal Integrated Products, Inc. 5 // 6 // AUTH: FB 7 // DATE: 19 SEP 02 8 // 9 // This file contains example initialization routines for the C8051F12x series 10 // of devices. 11 // 12 // This program uses the the 24.5 MHz internal oscillator multiplied by two 13 // for an effective SYSCLK of 49 MHz. This program also initializes and uses 14 // UART1 at bits per second. 15 // 16 // 17 // Target: C8051F12x 18 // Tool chain: KEIL C51 6.03 / KEIL EVAL C51 19 // 20 21 //----------------------------------------------------------------------------- 22 // Includes 23 //----------------------------------------------------------------------------- 24 #include // SFR declarations 25 #include // printf() and getchar() 26 27 //----------------------------------------------------------------------------- 28 // 16-bit SFR Definitions for 'F12x 29 //----------------------------------------------------------------------------- 30 31 sfr16 DP = 0x82; // data pointer 32 sfr16 ADC0 = 0xbe; // ADC0 data 33 sfr16 ADC0GT = 0xc4; // ADC0 greater than window 34 sfr16 ADC0LT = 0xc6; // ADC0 less than window 35 sfr16 RCAP2 = 0xca; // Timer2 capture/reload 36 sfr16 RCAP3 = 0xca; // Timer3 capture/reload 37 sfr16 RCAP4 = 0xca; // Timer4 capture/reload 38 sfr16 TMR2 = 0xcc; // Timer2 39 sfr16 TMR3 = 0xcc; // Timer3 40 sfr16 TMR4 = 0xcc; // Timer4 41 sfr16 DAC0 = 0xd2; // DAC0 data 42 sfr16 DAC1 = 0xd2; // DAC1 data 43 sfr16 PCA0CP5 = 0xe1; // PCA0 Module 5 capture 44 sfr16 PCA0CP2 = 0xe9; // PCA0 Module 2 capture 45 sfr16 PCA0CP3 = 0xeb; // PCA0 Module 3 capture 46 sfr16 PCA0CP4 = 0xed; // PCA0 Module 4 capture 47 sfr16 PCA0 = 0xf9; // PCA0 counter 48 sfr16 PCA0CP0 = 0xfb; // PCA0 Module 0 capture 49 sfr16 PCA0CP1 = 0xfd; // PCA0 Module 1 capture 50 51 //----------------------------------------------------------------------------- 52 // Global CONSTANTS 53 //----------------------------------------------------------------------------- 54 #define TRUE 1 C51 COMPILER V7.05 F12X_INIT_1 02/28/2006 13:19:24 PAGE 2 55 #define FALSE 0 56 57 #define INTCLK 24500000 // Internal oscillator frequency in Hz 58 #define SYSCLK 49000000 // Output of PLL derived from (INTCLK*2) 59 #define BAUDRATE 115200 // Baud rate of UART in bps 60 61 sbit LED = P1^6; // LED='1' means ON 62 sbit SW2 = P3^7; // SW2='0' means switch pressed 63 64 65 //----------------------------------------------------------------------------- 66 // Function PROTOTYPES 67 //----------------------------------------------------------------------------- 68 void main(void); 69 void SYSCLK_Init(void); 70 void PORT_Init(void); 71 void UART1_Init (void); 72 73 //----------------------------------------------------------------------------- 74 // MAIN Routine 75 //----------------------------------------------------------------------------- 76 77 void main (void) 78 { 79 1 80 1 WDTCN = 0xde; // disable watchdog timer 81 1 WDTCN = 0xad; 82 1 83 1 PORT_Init (); // initialize crossbar and GPIO 84 1 SYSCLK_Init (); // initialize oscillator 85 1 UART1_Init (); // initialize UART1 86 1 87 1 88 1 SFRPAGE = UART1_PAGE; // Direct printf output to UART1 89 1 printf("Hello\n"); // Print a string 90 1 91 1 while(1); 92 1 93 1 } 94 95 //----------------------------------------------------------------------------- 96 // Initialization Routines 97 //----------------------------------------------------------------------------- 98 99 //----------------------------------------------------------------------------- 100 // SYSCLK_Init 101 //----------------------------------------------------------------------------- 102 // 103 // This routine initializes the system clock to use the internal oscillator 104 // at 24.5 MHz multiplied by two using the PLL. 105 // 106 void SYSCLK_Init (void) 107 { 108 1 int i; // software timer 109 1 110 1 char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page 111 1 112 1 SFRPAGE = CONFIG_PAGE; // set SFR page 113 1 114 1 OSCICN = 0x83; // set internal oscillator to run 115 1 // at its maximum frequency 116 1 C51 COMPILER V7.05 F12X_INIT_1 02/28/2006 13:19:24 PAGE 3 117 1 CLKSEL = 0x00; // Select the internal osc. as 118 1 // the SYSCLK source 119 1 120 1 //Turn on the PLL and increase the system clock by a factor of M/N = 2 121 1 SFRPAGE = CONFIG_PAGE; 122 1 123 1 PLL0CN = 0x00; // Set internal osc. as PLL source 124 1 SFRPAGE = LEGACY_PAGE; 125 1 FLSCL = 0x10; // Set FLASH read time for 50MHz clk 126 1 // or less 127 1 SFRPAGE = CONFIG_PAGE; 128 1 PLL0CN |= 0x01; // Enable Power to PLL 129 1 PLL0DIV = 0x01; // Set Pre-divide value to N (N = 1) 130 1 PLL0FLT = 0x01; // Set the PLL filter register for 131 1 // a reference clock from 19 - 30 MHz 132 1 // and an output clock from 45 - 80 MHz 133 1 PLL0MUL = 0x02; // Multiply SYSCLK by M (M = 2) 134 1 135 1 for (i=0; i < 256; i++) ; // Wait at least 5us 136 1 PLL0CN |= 0x02; // Enable the PLL 137 1 while(!(PLL0CN & 0x10)); // Wait until PLL frequency is locked 138 1 CLKSEL = 0x02; // Select PLL as SYSCLK source 139 1 140 1 SFRPAGE = SFRPAGE_SAVE; // Restore SFR page 141 1 } 142 143 144 //----------------------------------------------------------------------------- 145 // PORT_Init 146 //----------------------------------------------------------------------------- 147 // 148 // This routine configures the crossbar and GPIO ports. 149 // 150 void PORT_Init (void) 151 { 152 1 char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page 153 1 154 1 SFRPAGE = CONFIG_PAGE; // set SFR page 155 1 156 1 XBR0 = 0x00; 157 1 XBR1 = 0x00; 158 1 XBR2 = 0x44; // Enable crossbar and weak pull-up 159 1 // Enable UART1 160 1 161 1 P0MDOUT |= 0x01; // Set TX1 pin to push-pull 162 1 P1MDOUT |= 0x40; // Set P1.6(LED) to push-pull 163 1 164 1 SFRPAGE = SFRPAGE_SAVE; // Restore SFR page 165 1 } 166 167 //----------------------------------------------------------------------------- 168 // UART1_Init 169 //----------------------------------------------------------------------------- 170 // 171 // Configure the UART1 using Timer1, for and 8-N-1. 172 // 173 void UART1_Init (void) 174 { 175 1 char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page 176 1 177 1 SFRPAGE = UART1_PAGE; 178 1 SCON1 = 0x10; // SCON1: mode 0, 8-bit UART, enable RX C51 COMPILER V7.05 F12X_INIT_1 02/28/2006 13:19:24 PAGE 4 179 1 180 1 SFRPAGE = TIMER01_PAGE; 181 1 TMOD &= ~0xF0; 182 1 TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload 183 1 184 1 185 1 if (SYSCLK/BAUDRATE/2/256 < 1) { 186 2 TH1 = -(SYSCLK/BAUDRATE/2); 187 2 CKCON |= 0x10; // T1M = 1; SCA1:0 = xx 188 2 } else if (SYSCLK/BAUDRATE/2/256 < 4) { 189 2 TH1 = -(SYSCLK/BAUDRATE/2/4); 190 2 CKCON &= ~0x13; // Clear all T1 related bits 191 2 CKCON |= 0x01; // T1M = 0; SCA1:0 = 01 192 2 } else if (SYSCLK/BAUDRATE/2/256 < 12) { 193 2 TH1 = -(SYSCLK/BAUDRATE/2/12); 194 2 CKCON &= ~0x13; // T1M = 0; SCA1:0 = 00 195 2 } else { 196 2 TH1 = -(SYSCLK/BAUDRATE/2/48); 197 2 CKCON &= ~0x13; // Clear all T1 related bits 198 2 CKCON |= 0x02; // T1M = 0; SCA1:0 = 10 199 2 } 200 1 201 1 TL1 = TH1; // initialize Timer1 202 1 TR1 = 1; // start Timer1 203 1 204 1 SFRPAGE = UART1_PAGE; 205 1 TI1 = 1; // Indicate TX1 ready 206 1 207 1 SFRPAGE = SFRPAGE_SAVE; // Restore SFR page 208 1 209 1 } 210 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 152 ---- CONSTANT SIZE = 7 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)