Here is the code. Basically, I layered code from several JAL
examples.
In I started with the USB Serial Lib and two switches/leds, and it
works.
I can view messages and enter chracters into a RealTerm app. I then
added the LCD routines to simultaneously view messages on it. Then
I added the ADC lib and added a AN0 input when switch (sw1) is
pressed.
Only the adc_hardware would compile.
I then downloaded the 15-Jan JalPack, i switched to the ADC lib but I
had to comment out many of the the pragma fuses. It did compile a hex
file.
However this hex would not work (probably I removed a needed fuse
though).
--
-----------------------------------------------------------------------------
-- ------------------------------------------------------
-- This file has been generated from:
-- * board: board_18f4550_af.jal
-- * test : test_usb_serial.jal
--
;@jallib section chipdef
-- chip setup
include 18f4550
-- even though the external crystal is 20 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 PLLDIV DIVIDE_BY_5__20MHZ_INPUT_
pragma target CPUDIV _OSC1_OSC2_SRC___1__96MHZ_PLL_SRC___2_
pragma target USBPLL CLOCK_SRC_FROM_96MHZ_PLL_2
pragma target OSC HS_PLL
pragma target FCMEN DISABLED
pragma target IESO DISABLED
pragma target PWRTE DISABLED -- power up timer
pragma target VREGEN ENABLED -- USB voltage regulator
pragma target VOLTAGE V20 -- brown out voltage
pragma target BROWNOUT DISABLED -- no brownout detection
pragma target WDTPS P32768 -- watch dog saler
setting
pragma target WDT DISABLED -- no watchdog
pragma target CCP2MUX RC1 -- CCP2 pin
pragma target PBADEN DIGITAL -- digital input port<0..4>
pragma target LPT1OSC DISABLED -- low power timer 1
pragma target MCLR EXTERNAL -- master reset on RE3
pragma target STVR DISABLED -- reset on stack
over/under flow
pragma target LVP DISABLED -- no low-voltage
programming
pragma target XINST ENABLED -- extended instruction
set
pragma target BACKBUG DISABLED -- background debugging
pragma target CP_0 DISABLED -- code block 0 not
protected
pragma target CP_1 DISABLED -- code block 1 not
protected
pragma target CP_2 DISABLED -- code block 2 not
protected
pragma target CP_3 DISABLED -- code block 3 not
protected
pragma target CPB DISABLED -- bootblock code not
write protected
pragma target CPD DISABLED -- eeprom code not
write protected
pragma target WRT_0 DISABLED -- table writeblock 0
not protected
pragma target WRT_1 DISABLED -- table write block 1
not protected
pragma target WRT_2 DISABLED -- table write block 2
not protected
pragma target WRT_3 DISABLED -- table write block 3
not protected
pragma target WRTB DISABLED -- bootblock not write
protected
pragma target WRTD DISABLED -- eeprom not write
protected
pragma target WRTC DISABLED -- config not write
protected
pragma target EBTR_0 DISABLED -- table read block 0 not
protected
pragma target EBTR_1 DISABLED -- table read block 1 not
protected
pragma target EBTR_2 DISABLED -- table read block 2 not
protected
pragma target EBTR_3 DISABLED -- table read block 3 not
protected
pragma target EBTRB DISABLED -- boot block not protected
;@jallib section lcd_hd44780_4
procedure PORTLCD'put(byte in x) is
var volatile bit x_0 at x:0
var volatile bit x_1 at x:1
var volatile bit x_2 at x:2
var volatile bit x_3 at x:3
pin_b1 = x_0
pin_b2 = x_1
pin_b3 = x_2
pin_b4 = x_3
end procedure
function PORTLCD'get() return byte is
var byte ret
var volatile bit ret_0 at ret:0 = pin_b1
var volatile bit ret_1 at ret:1 = pin_b2
var volatile bit ret_2 at ret:2 = pin_b3
var volatile bit ret_3 at ret:3 = pin_b4
return ret
end function
procedure PORTLCD_direction'put(byte in x) is
var volatile bit x_0 at x:0
var volatile bit x_1 at x:1
var volatile bit x_2 at x:2
var volatile bit x_3 at x:3
pin_b1_direction = x_0
pin_b2_direction = x_1
pin_b3_direction = x_2
pin_b4_direction = x_3
end procedure
function PORTLCD_direction'get() return byte is
var byte ret
var volatile bit ret_0 at ret:0 = pin_b1_direction
var volatile bit ret_1 at ret:1 = pin_b2_direction
var volatile bit ret_2 at ret:2 = pin_b3_direction
var volatile bit ret_3 at ret:3 = pin_b4_direction
return ret
end function
-- LCD IO definition
var bit lcd_rs is pin_d2 -- LCD command/data
select.
var bit lcd_rs_direction is pin_d2_direction
var bit lcd_en is pin_b0 -- LCD data trigger
var bit lcd_en_direction is pin_b0_direction
var byte lcd_dataport is portlcd -- LCD data port
var byte lcd_dataport_direction is portlcd_direction
const byte LCD_ROWS = 2 -- 2 lines
const byte LCD_CHARS = 16 -- 16 chars per line
;@jallib section led
--
enable_digital_io() -- disable analog I/O (if any)
--
-- You may want to change the selected pin:
var bit led1 is pin_c0 -- alias
pin_c0_direction = output
var bit led2 is pin_c2 -- alias
pin_c2_direction = output
--
var bit sw1 is pin_d7
pin_d7_direction = input
var bit sw2 is pin_d6
pin_d6_direction = input
lcd_rs_direction = output
lcd_en_direction = output
lcd_dataport_direction = output
include lcd_hd44780_4
include delay
include usb_serial
include print
include format
-- ok, now let's configure ADC
-- we want to measure using high resolution
-- (that's our choice, we could use low resolution as well)
const bit ADC_HIGH_RESOLUTION = high
--const bit ADC_HIGH_RESOLUTION = false
const bit adc_hardware_high_resolution = false
-- we said we want 1 analog channel...
const byte ADC_NCHANNEL = 1
const byte adc_hardware_nchan = 1
-- and no voltage reference ADC_NO_EXT_VREF or ADC_VREF_POS
const byte ADC_NVREF = 0
const byte adc_hardware_nvref = 0
const ADC_hardware_Rsource = 10_000 ;maximum source resistance
const bit PCFG3 = 1
const bit PCFG2 = 1
const bit PCFG1 = 1
const bit PCFG0 = 0
-- now we can include the library
include adc_hardware
-- constants
const byte str_welcome[] = "Using JALLIB USB Serial Demo app.
Modified by kw 28 jan 2012.\n"
const byte sw1_pressed[] = "Pressed sw1\r\n"
const byte sw2_pressed[] = "Pressed sw2\r\n"
const byte mydot[] = "."
-- variables
-- interrupts? No thanks
INTCON_GIE = false
for 4 loop -- blink LED 4 times to
indicate startup
led1 = on
delay_100ms(2)
led1 = off
delay_100ms(2)
end loop
const byte str1[] = "Hello world!" -- define strings
const byte str2[] = "third line"
const byte str3[] = "Pressed switch"
const byte str4[] = " "
lcd_init() -- initialize LCD
print_string(lcd, str1) -- show hello world!
lcd_cursor_position(2,0) -- to 3rd line
print_string(lcd, str2)
lcd_cursor_position(3,0) -- to 4th line
print_string(lcd, str3)
var byte counter1 = 0
var byte counter2 = 0
-- setup the USB serial library
usb_serial_init()
var bit has_shown_welcome_msg = true
var byte ch
--include adc
-- and run the initialization step
adc_init()
-- will periodically send those chars
var word wmeasure
var byte bmeasure
-- 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
if ch == "0" then
led1 = off
led2 = off
end if
if ch == "1" then
led1 = on
end if
if ch == "2" then
led2 = on
end if
end if
if sw1 == low then
_usec_delay(250000)
led1 = off
print_string( usb_serial_data, sw1_pressed )
-- get ADC result, on channel 0
-- this means we're currently reading on pin AN0 !
-- access results in high resolution
--wmeasure = adc_read(0)
wmeasure = adc_read(0)
-- wmeasure contains the result, as a word (byte*2)
counter1 = counter1 + 1 -- update counter
lcd_cursor_position(1,0) -- second line
print_string( lcd, str4 );
delay_100ms(3) -- wait a little
lcd_cursor_position(1,0) -- second line
print_word_dec(lcd, wmeasure) -- output in dec format
format_word_dec( usb_serial_data, wmeasure, 10, 0 )
delay_100ms(3) -- wait a little
end if
if sw2 == low then
_usec_delay(250000)
led2 = off
print_string( usb_serial_data, sw2_pressed )
counter2 = counter2 + 1 -- update counter
lcd_cursor_position(1,10) -- second line
print_byte_hex(lcd, counter2) -- output in hex format
delay_100ms(3) -- wait a little
end if
--counter = counter + 1 -- update counter
--lcd_cursor_position(1,0) -- second line
--print_byte_hex(lcd, counter) -- output in hex format
--delay_100ms(3) -- wait a little
end loop
On Jan 30, 1:25 am, [email protected] wrote:
> Updates:
> Owner: [email protected]
>
> Comment #1 on issue 174 by [email protected]: JAL 2.4.1 compile
> not like (include adc) for
> pic18f4550http://code.google.com/p/jallib/issues/detail?id=174
>
> Hi, please attach your code (18f4550_usb_serial_work_led2swlcd_adc.jal) and
> also try with a more recent jallib version
> (http://code.google.com/p/jallib/downloads/detail?name=jallib-pack-2.4...).
> I can't see any error (nor results).
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.