??? 11/25/05 07:39 Read: times |
#104148 - A simple UART program. Responding to: ???'s previous message |
Just try this out...Just copy and paste it in your compiler
#include <c8051F120.h> unsigned char temporary,temporary1; sbit LED = P1^6; void Init_Device(void); void main (void) { Init_Device(); while (1) { temporary1 = temporary; } } void serial_int(void) interrupt 4 { if(RI1) { RI1 = 0; temporary = SBUF0;} if(TI1) TI1 = 0; } void Tmr0_Int (void) interrupt 1 { static unsigned int count_sec = 0; TR0 = 0; TH0 = 0xF7; TL0 = 0x00; count_sec++; if(count_sec > 5000) { LED = !LED; SBUF1 = temporary; count_sec = 0; } TR0 = 1; } // Peripheral specific initialization functions, // Called from the Init_Device() function void Reset_Sources_Init() { WDTCN = 0xDE; WDTCN = 0xAD; } void Port_IO_Init() { // P0.0 - TX0 (UART0), Push-Pull, Digital // P0.1 - RX0 (UART0), Open-Drain, Digital // P0.2 - Unassigned, Open-Drain, Digital // P0.3 - Unassigned, Open-Drain, Digital // P0.4 - Unassigned, Open-Drain, Digital // P0.5 - Unassigned, Open-Drain, Digital // P0.6 - Unassigned, Open-Drain, Digital // P0.7 - Unassigned, Open-Drain, Digital // P1.0 - Unassigned, Open-Drain, Digital // P1.1 - Unassigned, Open-Drain, Digital // P1.2 - Unassigned, Open-Drain, Digital // P1.3 - Unassigned, Open-Drain, Digital // P1.4 - Unassigned, Open-Drain, Digital // P1.5 - Unassigned, Open-Drain, Digital // P1.6 - Unassigned, Push-Pull, Digital // P1.7 - Unassigned, Open-Drain, Digital // P2.0 - Unassigned, Open-Drain, Digital // P2.1 - Unassigned, Open-Drain, Digital // P2.2 - Unassigned, Open-Drain, Digital // P2.3 - Unassigned, Open-Drain, Digital // P2.4 - Unassigned, Open-Drain, Digital // P2.5 - Unassigned, Open-Drain, Digital // P2.6 - Unassigned, Open-Drain, Digital // P2.7 - Unassigned, Open-Drain, Digital // P3.0 - Unassigned, Open-Drain, Digital // P3.1 - Unassigned, Open-Drain, Digital // P3.2 - Unassigned, Open-Drain, Digital // P3.3 - Unassigned, Open-Drain, Digital // P3.4 - Unassigned, Open-Drain, Digital // P3.5 - Unassigned, Open-Drain, Digital // P3.6 - Unassigned, Open-Drain, Digital // P3.7 - Unassigned, Open-Drain, Digital SFRPAGE = CONFIG_PAGE; P0MDOUT = 0x01; P1MDOUT = 0x40; XBR0 = 0x04; XBR2 = 0x40; } void Oscillator_Init() { int i = 0; SFRPAGE = CONFIG_PAGE; SFRPAGE = LEGACY_PAGE; FLSCL = 0xB0; SFRPAGE = CONFIG_PAGE; PLL0CN |= 0x01; PLL0DIV = 0x01; PLL0FLT = 0x01; PLL0MUL = 0x04; for (i = 0; i < 15; i++); // Wait 5us for initialization PLL0CN |= 0x02; while ((PLL0CN & 0x10) == 0); CLKSEL = 0x02; OSCICN = 0x83; } void Timer_Init() { SFRPAGE = TIMER01_PAGE; TCON = 0x10; TMOD = 0x01; TH0 = 0xF7; SFRPAGE = TMR2_PAGE; TMR2CN = 0x04; TMR2CF = 0x08; RCAP2L = 0x82; RCAP2H = 0xFD; } void UART_Init() { SFRPAGE = UART0_PAGE; SCON0 = 0x50; SSTA0 = 0x15; } void Interrupts_Init() { IE = 0x92; } // Initialization function for device, // Call Init_Device() from your main program void Init_Device(void) { Reset_Sources_Init(); Port_IO_Init(); Oscillator_Init(); Timer_Init(); UART_Init(); Interrupts_Init(); } |
Topic | Author | Date |
getting started with f12xx DK | 01/01/70 00:00 | |
What's in the Kit | 01/01/70 00:00 | |
on cd | 01/01/70 00:00 | |
A simple UART program. | 01/01/70 00:00 | |
I love my board......but... | 01/01/70 00:00 | |
Learn to crawl, THEN learn to walk. | 01/01/70 00:00 | |
Blinky | 01/01/70 00:00 | |
tried that .. | 01/01/70 00:00 | |
The examples | 01/01/70 00:00 | |
This is contradictory. | 01/01/70 00:00 | |
i understand | 01/01/70 00:00 | |
good intention![]() | 01/01/70 00:00 |