| Swordfish Tutorial - ADC (Output to LCD) |
|
|
| Saturday, 04 April 2009 08:24 | |
|
This Analogue to Digital (ADC) PIC micro example is not only great for learning how to use ADC with Swordfish, but also to learn how a Function works. The Function will perform the required task/commands and then return with a Word variable called Result. you don't need to declare the variable "Result", as its the sole purpose of using a Function.
In this case, the Function is called "ADInAsVolt". It gets the ADC value on channel 0, and converts it to volts, and stores it in the Functions Result register. Just because the Function is at the start of the program does not mean that it is executed at the start - the first line to be executed is "ADCON1 = $07", and the program follows on from there. The command ADVal = ADInAsVolt instructs the program to call the function, and store the result in ADVal. Handy!
Device = 18F452 Clock = 20 // some LCD options... #option LCD_DATA = PORTD.4 #option LCD_RS = PORTD.2 #option LCD_EN = PORTD.3 // uses LCD and AD libraries... Include "LCD.bas" Include "ADC.bas" Include "convert.bas" Dim ADVal As Word // Read the AD port and scale for 0.00 - 5.00 volts... Function ADInAsVolt() As Word result = (ADC.Read(0) + 1) * 500 / 1024 End Function // Start Of Program... ADCON1 = %10000000 ADCON0.7 = 1 ADCON0.6 = 1 DelayMS (150) LCD.Cls // main program loop... While true ADVal = ADInAsVolt LCD.MoveCursor (1,1) LCD.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ") DelayMS(250) Wend
Note the PIC's power supply/oscillator are not shown
18F452 ADC Example
|
|
| Last Updated ( Friday, 24 April 2009 10:01 ) |
Whos Online
- andyo
- MrDEB
Forum Activity
LCD / 18F1320 - mrdeb Saturday, 20 March 2010 06:21 - [3 replies]
A 'throw-away" PIC board - mrdeb Thursday, 18 March 2010 06:19 - [32 replies]
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]





Nice. The TAP-28 boards are looking good. When I've had a buzzi...
The author (Hop) suggests to "set the target PIC's configuratio...
Graham, Thanks for fixing the spacing on the array. This is how i...
Thanks Graham, It is a problem with Flowcode because the demo wa...
Looks like you've pretty much solved every minor issue that was enc...
The low-cost servo does have one other feature. The origina...
I am not familiar with flowcode, though did you try powering the bo...
Hello there, I am still trying to get the LCD to work but I am pro...