| 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
- MrDEB
Forum Activity
simulation program - mrdeb Thursday, 11 March 2010 22:52 - [0 replies]
MARCHING ledS - mrdeb Thursday, 11 March 2010 19:13 - [3 replies]
REALISTIC LED candle flicker - mrdeb Wednesday, 10 March 2010 05:48 - [0 replies]
the LCD demo hello world - mrdeb Wednesday, 10 March 2010 05:41 - [29 replies]
USB problem - jon chandler Tuesday, 09 March 2010 11:31 - [3 replies]
Servo Module - andyo Tuesday, 09 March 2010 03:39 - [3 replies]
pic to ps2 communication - roshan Friday, 05 March 2010 01:30 - [7 replies]





If this wasn't a class project that had to be done on a PIC16F690 u...
I am going to send two data from ADC to USART(async mode) to serial...
I was thinking of battery with powered routers or powered for every...
50 rooms - wow. The XBee modules are very easy to use but I'm not ...
Thanks AndyO. What I have to do is design a device to monitor temp...
The circuit used for the remote sensor can be found here: [url]http...
plz i need help do u know from where i could download it or how cou...
hello everyone i'm trying to finish my final project and i want to ...