include 18f14k50
-- This file is the setup for my homebrew, 18f14k50 board
-- Currently it is a bare board, with just a PIC and a couple of headers
-- A 12 MHz external crystal and 15pf caps connected to OSC1/2
-- pin 17 (Vusb) with a 220 nF capacitor to the ground
-- The connection between PC and the 18F14k50
-- +5v to power the board (don't forget 100nf decoupling cap
-- data- wire to pin 18 (D-)
-- data+ wire to pin 19 (D+)
-- ground wire to the Vss of the PIC
-- even though the external crystal is 12 MHz, the configuration is such that
-- the CPU clock is derived from the 96 Mhz PLL clock (div2), therefore set
-- target frequency to 48 MHz
pragma target clock 48_000_000
-- fuses
pragma target CPUDIV P1 -- NO_CPU_SYSTEM_CLOCK_DIVIDE
pragma target USBDIV P1 -- USB_CLOCK_COMES_DIRECTLY_FROM_THE_OSC1_OSC2_OSCILLATOR_BLOCK_NO_DIVIDE
pragma target OSC HS
pragma target PLLEN P4 -- OSCILLATOR_MULTIPLIED_BY_4
pragma target FCMEN DISABLED
pragma target IESO DISABLED
pragma target PWRTE DISABLED -- power up timer
pragma target BROWNOUT DISABLED -- no brownout detection
pragma target VOLTAGE V30 -- brown out voltage
pragma target WDT DISABLED -- no watchdog
pragma target WDTPS P32K -- watch dog saler setting
pragma target MCLR EXTERNAL -- external reset
pragma target LVP DISABLED -- no low-voltage programming
pragma target XINST ENABLED -- extended instruction set
pragma target DEBUG DISABLED -- background debugging
pragma target CP0 DISABLED -- code block 0 not protected
pragma target CP1 DISABLED -- code block 1 not protected
pragma target CPB DISABLED -- bootblock code not write protected
pragma target WRT0 DISABLED -- table writeblock 0 not protected
pragma target WRT1 DISABLED -- table write block 1 not protected
pragma target WRTB DISABLED -- bootblock not write protected
pragma target WRTC DISABLED -- config not write protected
pragma target EBTR0 DISABLED -- table read block 0 not protected
pragma target EBTR1 DISABLED -- table read block 1 not protected
pragma target EBTRB DISABLED -- boot block not protected
pragma target HFOFST ENABLED -- THE_SYSTEM_CLOCK_IS_HELD_OFF_UNTIL_THE_HFINTOSC_IS_STABLE
include delay
include usb_serial
include print
-- constants
const byte str_welcome[] = "JALLIB USB Serial Demo app\n"
-- variables
-- interrupts? No thanks
INTCON_GIE = false
-- setup the USB serial library
usb_serial_init()
var bit has_shown_welcome_msg = true
var byte ch
-- main loop
forever loop
-- poll the usb ISR function on a regular base, in order to
-- serve the USB requests
usb_serial_flush()
-- check if USB device has been configured by the HOST
if ( usb_cdc_line_status() != 0x00 ) then
if !has_shown_welcome_msg then
has_shown_welcome_msg = true
print_string( usb_serial_data, str_welcome )
end if
else
has_shown_welcome_msg = false
end if
-- check for input character
if usb_serial_read( ch ) then
-- echo input character
usb_serial_data = ch
end if
end loop