Convert from 20MHz to 4 MHz
[pic-uart.git] / test.c
blobba873c393e3d6881476efb9e88d126571dd5728b
1 /*
2 toggle_led.c
3 Toggles an LED on Pin 1 of PORTB on a PIC16F627. Written
4 as a sample for the article on using SDCC and GPSIM in
5 Linux. http://www.micahcarrick.com/v2/content/view/14/4/
7 Compile: sdcc --debug -mpic14 -p16f628a test.c
8 Simulate: gpsim -c env.conf -s test.cod
12 /* Define processor and include header file. */
13 #define __16f628a
14 #include "pic/pic16f628a.h"
16 /* Setup chip configuration */
17 typedef unsigned int config;
18 config at 0x2007 __CONFIG = _CP_OFF &
19 _WDT_OFF &
20 _BODEN_OFF &
21 _PWRTE_OFF &
22 _ER_OSC_CLKOUT &
23 _MCLRE_ON &
24 _LVP_OFF;
26 #define b0 0x01 /* pin 1 on PORTB */
27 #define B_OUTPUTS 0xfa /* value used to setup TRISB */
30 /* TXSTA */
31 static void setup() {
32 /* PORTB.1 is an output pin */
33 TRISB = B_OUTPUTS;
34 /* USART setup */
35 //BRGH = 1; // baudrate class
36 SPBRG = 25;
38 SYNC = 0; /* Asynchronous */
39 SPEN = 1; /* Serial port enable*/
40 TXEN = 1; /* Tx enable */
43 static void send_byte(char alpha) {
44 TXREG = alpha;
47 void main(void) {
48 char alpha = 'a';
49 int i;
51 setup();
53 TXREG = alpha;
54 while(1) { /* Loop forever */
55 /* toggle bit 1 */
56 //PORTB = (PORTB ^ b0);
57 while (TRMT);
58 for (i = 0; i < 2000; i++);
59 send_byte(alpha);
60 alpha++;
61 if (alpha > 'z')
62 alpha = 'a';