Hello I was wondering if someone could help figure out why my code won't compile for the 16f722.
only seems to be a problem with the adc component.
thx in advance.D
Launching the compiler...
C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic16.flowcode.exe -v -t PIC16F722 "new722codeV1.c"
BoostC Optimizing C Compiler Version 6.95 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2009 Pavel Baranov
Copyright(C) 2004-2009 David Hobday
Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited
new722codeV1.c
Starting preprocessor: C:\PROGRA~1\MATRIX~1\FLOWCO~1\BoostC\pp.exe C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c -i C:\PROGRA~1\MATRIX~1\FLOWCO~1\BoostC\include -d _PIC16F722 -la -c2 -o C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.pp -v -d _BOOSTC -d _PIC16
...........................
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(661:9): error: unknown identifier 'adresh'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(661:2): error: error in expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(661:2): error: failed to generate expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(676:13): error: unknown identifier 'adresh'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(676:13): error: invalid operand 'adresh'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(676:20): error: failed to generate expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(676:20): error: invalid operand '<<'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(676:10): error: failed to generate expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:23): error: unknown identifier 'adresl'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:23): error: invalid operand 'adresl'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:30): error: failed to generate expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:30): error: invalid operand '>>'
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:20): error: failed to generate expression
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:20): error: invalid operand '| '
C:\Users\Dell\Desktop\ELECTRONICS\new722codeV1.c(677:10): error: failed to generate expression
new722codeV1.c success
failure
......
Return code = 1
Flowcode was unable to compile the flowchart's C code due to the following errors:
If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.
FINISHED
help with 16F722
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: help with 16F722
Hello Dan.
This is a Flowcode V4 problem, so please post this question into that forum. It would also be a good idea to post your FCF and C files so we can see exactly what is going on.
This is a Flowcode V4 problem, so please post this question into that forum. It would also be a good idea to post your FCF and C files so we can see exactly what is going on.
Re: help with 16F722
hi steve
sorry for posting here but I can't post in the v4 forum even after following the instructions and I'm down to the wire to get this done.
Here is the C code.
//************************************************************************************
//**
//** File name: C:\Documents and Settings\Dan\Desktop\beer code2010\new722codeV1.c
//** Generated by: Flowcode v4.2.3.58
//** Date: Friday, March 05, 2010 00:03:07
//** Licence: Professional
//** Registered to: Daniel Kehoe
//**
//**
//** http://www.matrixmultimedia.com
//************************************************************************************
#define MX_PIC
//Defines for microcontroller
#define P16F722
#define MX_SPI
#define MX_SPI_C
#define MX_SPI_SDI 4
#define MX_SPI_SDO 5
#define MX_SPI_SCK 3
#define MX_UART
#define MX_UART_C
#define MX_UART_TX 6
#define MX_UART_RX 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_C
#define MX_I2C_SDA 4
#define MX_I2C_SCL 3
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 2
#define MX_PWM_TRIS2 trisc
#define MX_PWM_2 1
#define MX_PWM_TRIS2a trisb
#define MX_PWM_2a 3
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
//Variable declarations
char FCV_TEC;
char FCV_FAN;
short FCV_COLDPLATE;
//Defines:
/**** Macro Substitutions ****
portb = D1 Port
trisb = D1 Data Direction
portb = D2 Port
trisb = D2 Data Direction
portb = D3 Port
trisb = D3 Data Direction
portb = D4 Port
trisb = D4 Data Direction
portb = RS Port
trisb = RS Data Direction
portb = E Port
trisb = E Data Direction
0 = Data 1_Pin
1 = Data 2 Pin
2 = Data 3 Pin
3 = Data 4 Pin
4 = RS Pin
5 = Enable Pin
LCD_1311602 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/
//component connections
#define LCD_1311602_PORT0 portb
#define LCD_1311602_TRIS0 trisb
#define LCD_1311602_PORT1 portb
#define LCD_1311602_TRIS1 trisb
#define LCD_1311602_PORT2 portb
#define LCD_1311602_TRIS2 trisb
#define LCD_1311602_PORT3 portb
#define LCD_1311602_TRIS3 trisb
#define LCD_1311602_PORT4 portb
#define LCD_1311602_TRIS4 trisb
#define LCD_1311602_PORT5 portb
#define LCD_1311602_TRIS5 trisb
#define LCD_1311602_BIT0 0
#define LCD_1311602_BIT1 1
#define LCD_1311602_BIT2 2
#define LCD_1311602_BIT3 3
#define LCD_1311602_RS 4
#define LCD_1311602_E 5
#define LCD_1311602_ROWCNT 2
#define LCD_1311602_COLCNT 16
#ifdef _BOOSTC
#define LCD_1311602_DELAY delay_10us(10)
#endif
#ifdef _C2C_
#define LCD_1311602_DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_1311602_DELAY __delay_us(120)
#endif
#ifndef LCD_1311602_DELAY
#define LCD_1311602_DELAY delay_us(100)
#endif
//LCDDisplay0: //Macro function declarations
void FCD_LCDDisplay0_RawSend(char in, char mask);
void FCD_LCDDisplay0_Start();
void FCD_LCDDisplay0_Clear();
void FCD_LCDDisplay0_PrintASCII(char Character);
void FCD_LCDDisplay0_Command(char in);
void FCD_LCDDisplay0_Cursor(char x, char y);
void FCD_LCDDisplay0_PrintNumber(short Number);
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String);
void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions);
void FCD_LCDDisplay0_ClearLine(char Line);
void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7);
//Defines:
/**** Macro Substitutions ****
0 = Which ADC Channel
40 = Acquisition time
3 = Conversion Speed
0 = VRef+ Option
500 = VRef Voltage x 0.01V
******************************/
//ADC0: //Macro function declarations
void FCD_ADC0_SampleADC();
char FCD_ADC0_ReadAsByte();
short FCD_ADC0_ReadAsInt();
float FCD_ADC0_ReadAsVoltage();
void FCD_ADC0_ReadAsString(char* FCR_RETVAL, char FCR_RETVAL_SIZE);
//Defines:
/**** Macro Substitutions ****
90 = Timer 2 Rollover Value
0x05 = Timer 2 Prescaler Value
%c = Unused
0 = Alternate Pin FCD_PWM0_Enable
******************************/
//PWM0: //Macro function declarations
void FCD_PWM0_Enable(char nIdx);
void FCD_PWM0_Disable(char nIdx);
void FCD_PWM0_SetDutyCycle(char nIdx, char nDuty);
void FCD_PWM0_ChangePeriod(char nPeriodVal, char nPrescalerVal);
void FCD_PWM0_SetDutyCycle10bit(char nIdx, short nDuty);
//LCDDisplay0: //Macro implementations
void FCD_LCDDisplay0_RawSend(char in, char mask)
{
unsigned char pt;
clear_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_PORT4, LCD_1311602_RS);
clear_bit(LCD_1311602_PORT5, LCD_1311602_E);
pt = ((in >> 4) & 0x0f);
if (pt & 0x01)
set_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
if (pt & 0x02)
set_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
if (pt & 0x04)
set_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
if (pt & 0x08)
set_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
if (mask)
set_bit(LCD_1311602_PORT4, LCD_1311602_RS);
LCD_1311602_DELAY;
set_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
clear_bit (LCD_1311602_PORT5, LCD_1311602_E);
pt = (in & 0x0f);
LCD_1311602_DELAY;
clear_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_PORT4, LCD_1311602_RS);
clear_bit(LCD_1311602_PORT5, LCD_1311602_E);
if (pt & 0x01)
set_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
if (pt & 0x02)
set_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
if (pt & 0x04)
set_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
if (pt & 0x08)
set_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
if (mask)
set_bit(LCD_1311602_PORT4, LCD_1311602_RS);
LCD_1311602_DELAY;
set_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
clear_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
}
void FCD_LCDDisplay0_Start()
{
clear_bit(LCD_1311602_TRIS0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_TRIS1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_TRIS2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_TRIS3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_TRIS4, LCD_1311602_RS);
clear_bit(LCD_1311602_TRIS5, LCD_1311602_E);
Wdt_Delay_Ms(12);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x32, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x2c, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x06, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x0c, 0);
Wdt_Delay_Ms(2);
//clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Clear()
{
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintASCII(char Character)
{
FCD_LCDDisplay0_RawSend(Character, 0x10);
}
void FCD_LCDDisplay0_Command(char in)
{
FCD_LCDDisplay0_RawSend(in, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Cursor(char x, char y)
{
#if (LCD_1311602_ROWCNT == 1)
y=0x80;
#endif
#if (LCD_1311602_ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
#endif
#if (LCD_1311602_ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;
#if (LCD_1311602_COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif
#if (LCD_1311602_COLCNT == 20)
else if (y==2)
y=0x94;
else
y=0xd4;
#endif
#endif
FCD_LCDDisplay0_RawSend(y+x, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintNumber(short Number)
{
short tmp_int;
char tmp_byte;
if (Number < 0)
{
FCD_LCDDisplay0_RawSend('-', 0x10);
Number = 0 - Number;
}
tmp_int = Number;
if (Number >= 10000)
{
tmp_byte = tmp_int / 10000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 10000;
tmp_byte--;
}
}
if (Number >= 1000)
{
tmp_byte = tmp_int / 1000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 1000;
tmp_byte--;
}
}
if (Number >= 100)
{
tmp_byte = tmp_int / 100;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 100;
tmp_byte--;
}
}
if (Number >= 10)
{
tmp_byte = tmp_int / 10;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 10;
tmp_byte--;
}
}
FCD_LCDDisplay0_RawSend('0' + tmp_int, 0x10);
}
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String)
{
char idx = 0;
for (idx=0; idx<MSZ_String; idx++)
{
#ifdef _BOOSTC
if (String[idx] == 0)
{
break;
}
FCD_LCDDisplay0_RawSend(String[idx], 0x10);
#endif
#ifdef HI_TECH_C
if (*String == 0)
{
break;
}
FCD_LCDDisplay0_RawSend(*String, 0x10);
String++;
#endif
}
}
void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions)
{
char cmd = 0;
char count;
//Choose the direction
switch (Direction)
{
case 0:
case 'l':
case 'L':
cmd = 0x18;
break;
case 1:
case 'r':
case 'R':
cmd = 0x1C;
break;
default:
break;
}
//If direction accepted then scroll the specified amount
if (cmd)
{
for (count = 0; count < Num_Positions; count++)
FCD_LCDDisplay0_Command(cmd);
}
}
void FCD_LCDDisplay0_ClearLine(char Line)
{
char count;
char rowcount;
//Define number of columns per line
#if (LCD_1311602_ROWCNT == 1)
rowcount=80;
#endif
#if (LCD_1311602_ROWCNT == 2)
rowcount=40;
#endif
#if (LCD_1311602_ROWCNT == 4)
#if (LCD_1311602_COLCNT == 16)
rowcount=16;
#endif
#if (LCD_1311602_COLCNT == 20)
rowcount=20;
#endif
#endif
//Start at beginning of the line
FCD_LCDDisplay0_Cursor (0, Line);
//Send out spaces to clear line
for (count = 0; count < rowcount; count++)
FCD_LCDDisplay0_RawSend(' ', 0x10);
//Move back to the beginning of the line.
FCD_LCDDisplay0_Cursor (0, Line);
}
void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7)
{
//set CGRAM address
FCD_LCDDisplay0_RawSend(64 + (nIdx << 3), 0);
delay_ms(2);
//write CGRAM data
FCD_LCDDisplay0_RawSend(d0, 0x10);
FCD_LCDDisplay0_RawSend(d1, 0x10);
FCD_LCDDisplay0_RawSend(d2, 0x10);
FCD_LCDDisplay0_RawSend(d3, 0x10);
FCD_LCDDisplay0_RawSend(d4, 0x10);
FCD_LCDDisplay0_RawSend(d5, 0x10);
FCD_LCDDisplay0_RawSend(d6, 0x10);
FCD_LCDDisplay0_RawSend(d7, 0x10);
//Clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
delay_ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
delay_ms(2);
}
//ADC0: //Macro implementations
void FCD_ADC0_SampleADC()
{
/*******Supported Devices******************************************************************
// 16F722, 16F723, 16F724, 16F726, 16F727, 16F1933, 16F1934, 16F1936, 16F1937, 16F1939
******************************************************************************************/
#define MX_ADC_CHANNEL 0
#define MX_ADC_SAMP_TIME 40
#define MX_ADC_CONV_SP 3
#define MX_ADC_VREF_OPT 0
//set up ADC conversion
char old_tris, cnt;
adcon1 = (MX_ADC_CONV_SP & 0x07) << 4;
//find appropriate bit
#if (MX_ADC_CHANNEL == 0)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 1)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 2)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 3)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x08
#define MX_ADC_ANSEL_REG ansela
#if (MX_ADC_VREF_OPT != 0)
#pragma error "Target device is currently using AN3 for VREF+"
#endif
#endif
#if (MX_ADC_CHANNEL == 4)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x20
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 5)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL == 6)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL == 7)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL ==
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 9)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x08
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 10)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 11)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x10
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 12)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 13)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x20
#define MX_ADC_ANSEL_REG anselb
#endif
//sanity check
#ifndef MX_ADC_TRIS_REG
#pragma error "ADC Type 18 conversion code error - please contact technical support"
#endif
//assign VREF functionality
#if (MX_ADC_VREF_OPT != 0)
st_bit(adcon1, ADREF1);
#endif
//store old tris value, and set the i/o pin as an analogue input
old_tris = MX_ADC_TRIS_REG;
MX_ADC_TRIS_REG = MX_ADC_TRIS_REG | MX_ADC_TRIS_MSK;
MX_ADC_ANSEL_REG = MX_ADC_ANSEL_REG | MX_ADC_TRIS_MSK;
//turn ADC on
adcon0 = 0x01 | (MX_ADC_CHANNEL << 2);
//wait the acquisition time
cnt = 0;
while (cnt < MX_ADC_SAMP_TIME) cnt++;
//begin conversion and wait until it has finished
adcon0 = adcon0 | 0x02;
while (adcon0 & 0x02);
//restore old tris value, and reset adc registers
MX_ADC_TRIS_REG = old_tris;
MX_ADC_ANSEL_REG = 0x00;
adcon0 = 0x00;
#undef MX_ADC_TRIS_REG
#undef MX_ADC_TRIS_MSK
#undef MX_ADC_ANSEL_REG
#undef MX_ADC_SAMP_TIME
#undef MX_ADC_CHANNEL
#undef MX_ADC_CONV_SP
#undef MX_ADC_VREF_OPT
}
char FCD_ADC0_ReadAsByte()
{
FCD_ADC0_SampleADC();
#ifdef adres
return adres;
#else
return adresh;
#endif
}
short FCD_ADC0_ReadAsInt()
{
short iRetVal;
FCD_ADC0_SampleADC();
#ifdef adres
iRetVal = (adres << 2);
#else
iRetVal = (adresh << 2);
iRetVal = iRetVal | (adresl >> 6);
#endif
return (iRetVal);
}
float FCD_ADC0_ReadAsVoltage()
{
int iSample;
float fSample, fVoltage, fVperDiv;
#define MX_ADC_VREF_V 500
iSample = FCD_ADC0_ReadAsInt(); //Read as 10-bit Integer
#ifdef _BOOSTC
fVoltage = float32_from_int32(MX_ADC_VREF_V); //Convert reference voltage count to floating point (0 - 500 x 10mV)
fVoltage = float32_mul(fVoltage, 0.01); //Convert reference voltage count to actual voltage (0 - 5)
fVperDiv = float32_mul(fVoltage, 0.000976); //Convert actual voltage to voltage per division (VRef / 1024)
fSample = float32_from_int32(iSample); //Convert to floating point variable
fVoltage = float32_mul(fSample, fVperDiv); //Calculate floating point voltage
#endif
#ifdef HI_TECH_C
fVoltage = MX_ADC_VREF_V; //Convert reference voltage count to floating point (0 - 500 x 10mV)
fVoltage = fVoltage * 0.01; //Convert reference voltage count to actual voltage (0 - 5)
fVperDiv = fVoltage * 0.000976; //Convert actual voltage to voltage per division (VRef / 1024)
fSample = iSample; //Convert to floating point variable
fVoltage = fSample * fVperDiv; //Calculate floating point voltage
#endif
#undef MX_ADC_VREF_V
return (fVoltage);
}
void FCD_ADC0_ReadAsString(char* FCR_RETVAL, char FCR_RETVAL_SIZE)
{
float fVoltage;
fVoltage = FCD_ADC0_ReadAsVoltage();
FCI_FLOAT_TO_STRING(fVoltage, 2, FCR_RETVAL, FCR_RETVAL_SIZE); //Convert to String
}
//PWM0: //Macro implementations
void FCD_PWM0_Enable(char nIdx)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#else
#ifndef MX_PWM_CNT
#pragma error FCD file error (no MX_PWM_CNT)
#endif
#if (MX_PWM_CNT < 1)
#pragma error FCD file error (MX_PWM_CNT < 1)
#endif
#if (MX_PWM_CNT > 2)
#pragma error FCD file error (MX_PWM_CNT > 2)
#endif
#ifndef MX_PWM_TRIS1
#pragma error FCD file error (no MX_PWM_TRIS1)
#endif
#ifndef MX_PWM_1
#pragma error FCD file error (no MX_PWM_1)
#endif
#if (MX_PWM_CNT == 2)
#ifndef MX_PWM_TRIS2
#pragma error FCD file error (no MX_PWM_TRIS2)
#endif
#ifndef MX_PWM_2
#pragma error FCD file error (no MX_PWM_2)
#endif
#endif
#if (0 == 1)
#ifndef MX_PWM_TRIS1a
#pragma error PWM component error (using alternative, but no MX_PWM_TRIS1a)
#define MX_PWM_ALT_ERROR
#endif
#ifndef MX_PWM_1a
#pragma error PWM component error (using alternative, but no MX_PWM_1a)
#define MX_PWM_ALT_ERROR
#endif
#endif
#if (0 == 2)
#ifndef MX_PWM_TRIS2a
#pragma error PWM component error (using alternative, but no MX_PWM_TRIS2a)
#define MX_PWM_ALT_ERROR
#endif
#ifndef MX_PWM_2a
#pragma error PWM component error (using alternative, but no MX_PWM_2a)
#define MX_PWM_ALT_ERROR
#endif
#endif
#endif
#ifdef MX_PWM
pr2 = 90;
t2con = 0x05;
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccp1con = 0x0C;
#if (0 == 1)
#ifndef MX_PWM_ALT_ERROR
clear_bit(MX_PWM_TRIS1a, MX_PWM_1a);
#endif
#else
clear_bit(MX_PWM_TRIS1, MX_PWM_1);
#endif
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccp2con = 0x0C;
#if (0 == 2)
#ifndef MX_PWM_ALT_ERROR
clear_bit(MX_PWM_TRIS2a, MX_PWM_2a);
#endif
#else
clear_bit(MX_PWM_TRIS2, MX_PWM_2);
#endif
}
#endif
#endif
#ifdef MX_PWM_ALT_ERROR
#undef MX_PWM_ALT_ERROR
#endif
}
void FCD_PWM0_Disable(char nIdx)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccp1con = 0x00;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccp2con = 0x00;
}
#endif
#endif
}
void FCD_PWM0_SetDutyCycle(char nIdx, char nDuty)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccpr1l = nDuty;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccpr2l = nDuty;
}
#endif
#endif
}
void FCD_PWM0_ChangePeriod(char nPeriodVal, char nPrescalerVal)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
pr2 = nPeriodVal;
switch (nPrescalerVal)
{
case 1:
t2con = 0x04;
break;
case 4:
t2con = 0x05;
break;
case 16:
t2con = 0x06;
break;
}
#endif
}
void FCD_PWM0_SetDutyCycle10bit(char nIdx, short nDuty)
{
char nCCPxCONtemp;
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccpr1l = (nDuty & 0x3FC) >> 2;
nDuty = (nDuty & 0x03) << 4;
nCCPxCONtemp = (ccp1con & 0xCF) | nDuty;
ccp1con = nCCPxCONtemp;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccpr2l = (nDuty & 0x3FC) >> 2;
nDuty = (nDuty & 0x03) << 4;
nCCPxCONtemp = (ccp2con & 0xCF) | nDuty;
ccp2con = nCCPxCONtemp;
}
#endif
#endif
}
//Macro implementations
void main()
{
//Initialisation
ansela = 0x00;
anselb = 0x00;
//Interrupt initialisation code
option_reg = 0xC0;
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Start
FCD_LCDDisplay0_Start();
//Call Component Macro
//Call Component Macro: PWM(0)::Enable(1)
FCD_PWM0_Enable(1);
//Call Component Macro
//Call Component Macro: PWM(0)::Enable(2)
FCD_PWM0_Enable(2);
//Loop
//Loop: While 1
while (1)
{
//Output
//Output: 1 -> C3
trisc = trisc & 0xf7;
if (1)
portc = (portc & 0xf7) | 0x08;
else
portc = portc & 0xf7;
//Call Component Macro
//Call Component Macro: PWM(0)::SetDutyCycle(1, tec)
FCD_PWM0_SetDutyCycle(1, FCV_TEC);
//Call Component Macro
//Call Component Macro: PWM(0)::SetDutyCycle(2, fan)
FCD_PWM0_SetDutyCycle(2, FCV_FAN);
//Call Component Macro
//Call Component Macro: coldplate=ADC(0)::ReadAsByte
FCV_COLDPLATE = FCD_ADC0_ReadAsByte();
//Delay
//Delay: 250 ms
delay_ms(250);
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintNumber(coldplate)
FCD_LCDDisplay0_PrintNumber(FCV_COLDPLATE);
//Decision
//Decision: coldplate< 211?
if (FCV_COLDPLATE< 211)
{
//Calculation
//Calculation:
// tec = 91
// fan = 91
FCV_TEC = 91;
FCV_FAN = 91;
}
//Decision
//Decision: coldplate>211?
if (FCV_COLDPLATE>211)
{
//Decision
//Decision: coldplate>221?
if (FCV_COLDPLATE>221)
{
//Calculation
//Calculation:
// tec = 0
// fan = 0
FCV_TEC = 0;
FCV_FAN = 0;
} else {
//Calculation
//Calculation:
// tec = 91
// fan = 30
FCV_TEC = 91;
FCV_FAN = 30;
}
}
//Delay
//Delay: 1 s
delay_s(1);
}
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}
sorry for posting here but I can't post in the v4 forum even after following the instructions and I'm down to the wire to get this done.
Here is the C code.
//************************************************************************************
//**
//** File name: C:\Documents and Settings\Dan\Desktop\beer code2010\new722codeV1.c
//** Generated by: Flowcode v4.2.3.58
//** Date: Friday, March 05, 2010 00:03:07
//** Licence: Professional
//** Registered to: Daniel Kehoe
//**
//**
//** http://www.matrixmultimedia.com
//************************************************************************************
#define MX_PIC
//Defines for microcontroller
#define P16F722
#define MX_SPI
#define MX_SPI_C
#define MX_SPI_SDI 4
#define MX_SPI_SDO 5
#define MX_SPI_SCK 3
#define MX_UART
#define MX_UART_C
#define MX_UART_TX 6
#define MX_UART_RX 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_C
#define MX_I2C_SDA 4
#define MX_I2C_SCL 3
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 2
#define MX_PWM_TRIS2 trisc
#define MX_PWM_2 1
#define MX_PWM_TRIS2a trisb
#define MX_PWM_2a 3
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
//Variable declarations
char FCV_TEC;
char FCV_FAN;
short FCV_COLDPLATE;
//Defines:
/**** Macro Substitutions ****
portb = D1 Port
trisb = D1 Data Direction
portb = D2 Port
trisb = D2 Data Direction
portb = D3 Port
trisb = D3 Data Direction
portb = D4 Port
trisb = D4 Data Direction
portb = RS Port
trisb = RS Data Direction
portb = E Port
trisb = E Data Direction
0 = Data 1_Pin
1 = Data 2 Pin
2 = Data 3 Pin
3 = Data 4 Pin
4 = RS Pin
5 = Enable Pin
LCD_1311602 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/
//component connections
#define LCD_1311602_PORT0 portb
#define LCD_1311602_TRIS0 trisb
#define LCD_1311602_PORT1 portb
#define LCD_1311602_TRIS1 trisb
#define LCD_1311602_PORT2 portb
#define LCD_1311602_TRIS2 trisb
#define LCD_1311602_PORT3 portb
#define LCD_1311602_TRIS3 trisb
#define LCD_1311602_PORT4 portb
#define LCD_1311602_TRIS4 trisb
#define LCD_1311602_PORT5 portb
#define LCD_1311602_TRIS5 trisb
#define LCD_1311602_BIT0 0
#define LCD_1311602_BIT1 1
#define LCD_1311602_BIT2 2
#define LCD_1311602_BIT3 3
#define LCD_1311602_RS 4
#define LCD_1311602_E 5
#define LCD_1311602_ROWCNT 2
#define LCD_1311602_COLCNT 16
#ifdef _BOOSTC
#define LCD_1311602_DELAY delay_10us(10)
#endif
#ifdef _C2C_
#define LCD_1311602_DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_1311602_DELAY __delay_us(120)
#endif
#ifndef LCD_1311602_DELAY
#define LCD_1311602_DELAY delay_us(100)
#endif
//LCDDisplay0: //Macro function declarations
void FCD_LCDDisplay0_RawSend(char in, char mask);
void FCD_LCDDisplay0_Start();
void FCD_LCDDisplay0_Clear();
void FCD_LCDDisplay0_PrintASCII(char Character);
void FCD_LCDDisplay0_Command(char in);
void FCD_LCDDisplay0_Cursor(char x, char y);
void FCD_LCDDisplay0_PrintNumber(short Number);
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String);
void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions);
void FCD_LCDDisplay0_ClearLine(char Line);
void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7);
//Defines:
/**** Macro Substitutions ****
0 = Which ADC Channel
40 = Acquisition time
3 = Conversion Speed
0 = VRef+ Option
500 = VRef Voltage x 0.01V
******************************/
//ADC0: //Macro function declarations
void FCD_ADC0_SampleADC();
char FCD_ADC0_ReadAsByte();
short FCD_ADC0_ReadAsInt();
float FCD_ADC0_ReadAsVoltage();
void FCD_ADC0_ReadAsString(char* FCR_RETVAL, char FCR_RETVAL_SIZE);
//Defines:
/**** Macro Substitutions ****
90 = Timer 2 Rollover Value
0x05 = Timer 2 Prescaler Value
%c = Unused
0 = Alternate Pin FCD_PWM0_Enable
******************************/
//PWM0: //Macro function declarations
void FCD_PWM0_Enable(char nIdx);
void FCD_PWM0_Disable(char nIdx);
void FCD_PWM0_SetDutyCycle(char nIdx, char nDuty);
void FCD_PWM0_ChangePeriod(char nPeriodVal, char nPrescalerVal);
void FCD_PWM0_SetDutyCycle10bit(char nIdx, short nDuty);
//LCDDisplay0: //Macro implementations
void FCD_LCDDisplay0_RawSend(char in, char mask)
{
unsigned char pt;
clear_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_PORT4, LCD_1311602_RS);
clear_bit(LCD_1311602_PORT5, LCD_1311602_E);
pt = ((in >> 4) & 0x0f);
if (pt & 0x01)
set_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
if (pt & 0x02)
set_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
if (pt & 0x04)
set_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
if (pt & 0x08)
set_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
if (mask)
set_bit(LCD_1311602_PORT4, LCD_1311602_RS);
LCD_1311602_DELAY;
set_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
clear_bit (LCD_1311602_PORT5, LCD_1311602_E);
pt = (in & 0x0f);
LCD_1311602_DELAY;
clear_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_PORT4, LCD_1311602_RS);
clear_bit(LCD_1311602_PORT5, LCD_1311602_E);
if (pt & 0x01)
set_bit(LCD_1311602_PORT0, LCD_1311602_BIT0);
if (pt & 0x02)
set_bit(LCD_1311602_PORT1, LCD_1311602_BIT1);
if (pt & 0x04)
set_bit(LCD_1311602_PORT2, LCD_1311602_BIT2);
if (pt & 0x08)
set_bit(LCD_1311602_PORT3, LCD_1311602_BIT3);
if (mask)
set_bit(LCD_1311602_PORT4, LCD_1311602_RS);
LCD_1311602_DELAY;
set_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
clear_bit (LCD_1311602_PORT5, LCD_1311602_E);
LCD_1311602_DELAY;
}
void FCD_LCDDisplay0_Start()
{
clear_bit(LCD_1311602_TRIS0, LCD_1311602_BIT0);
clear_bit(LCD_1311602_TRIS1, LCD_1311602_BIT1);
clear_bit(LCD_1311602_TRIS2, LCD_1311602_BIT2);
clear_bit(LCD_1311602_TRIS3, LCD_1311602_BIT3);
clear_bit(LCD_1311602_TRIS4, LCD_1311602_RS);
clear_bit(LCD_1311602_TRIS5, LCD_1311602_E);
Wdt_Delay_Ms(12);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x33, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x32, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x2c, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x06, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x0c, 0);
Wdt_Delay_Ms(2);
//clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Clear()
{
FCD_LCDDisplay0_RawSend(0x01, 0);
Wdt_Delay_Ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintASCII(char Character)
{
FCD_LCDDisplay0_RawSend(Character, 0x10);
}
void FCD_LCDDisplay0_Command(char in)
{
FCD_LCDDisplay0_RawSend(in, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_Cursor(char x, char y)
{
#if (LCD_1311602_ROWCNT == 1)
y=0x80;
#endif
#if (LCD_1311602_ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
#endif
#if (LCD_1311602_ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;
#if (LCD_1311602_COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif
#if (LCD_1311602_COLCNT == 20)
else if (y==2)
y=0x94;
else
y=0xd4;
#endif
#endif
FCD_LCDDisplay0_RawSend(y+x, 0);
Wdt_Delay_Ms(2);
}
void FCD_LCDDisplay0_PrintNumber(short Number)
{
short tmp_int;
char tmp_byte;
if (Number < 0)
{
FCD_LCDDisplay0_RawSend('-', 0x10);
Number = 0 - Number;
}
tmp_int = Number;
if (Number >= 10000)
{
tmp_byte = tmp_int / 10000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 10000;
tmp_byte--;
}
}
if (Number >= 1000)
{
tmp_byte = tmp_int / 1000;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 1000;
tmp_byte--;
}
}
if (Number >= 100)
{
tmp_byte = tmp_int / 100;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 100;
tmp_byte--;
}
}
if (Number >= 10)
{
tmp_byte = tmp_int / 10;
FCD_LCDDisplay0_RawSend('0' + tmp_byte, 0x10);
while (tmp_byte > 0)
{
tmp_int = tmp_int - 10;
tmp_byte--;
}
}
FCD_LCDDisplay0_RawSend('0' + tmp_int, 0x10);
}
void FCD_LCDDisplay0_PrintString(char* String, char MSZ_String)
{
char idx = 0;
for (idx=0; idx<MSZ_String; idx++)
{
#ifdef _BOOSTC
if (String[idx] == 0)
{
break;
}
FCD_LCDDisplay0_RawSend(String[idx], 0x10);
#endif
#ifdef HI_TECH_C
if (*String == 0)
{
break;
}
FCD_LCDDisplay0_RawSend(*String, 0x10);
String++;
#endif
}
}
void FCD_LCDDisplay0_ScrollDisplay(char Direction, char Num_Positions)
{
char cmd = 0;
char count;
//Choose the direction
switch (Direction)
{
case 0:
case 'l':
case 'L':
cmd = 0x18;
break;
case 1:
case 'r':
case 'R':
cmd = 0x1C;
break;
default:
break;
}
//If direction accepted then scroll the specified amount
if (cmd)
{
for (count = 0; count < Num_Positions; count++)
FCD_LCDDisplay0_Command(cmd);
}
}
void FCD_LCDDisplay0_ClearLine(char Line)
{
char count;
char rowcount;
//Define number of columns per line
#if (LCD_1311602_ROWCNT == 1)
rowcount=80;
#endif
#if (LCD_1311602_ROWCNT == 2)
rowcount=40;
#endif
#if (LCD_1311602_ROWCNT == 4)
#if (LCD_1311602_COLCNT == 16)
rowcount=16;
#endif
#if (LCD_1311602_COLCNT == 20)
rowcount=20;
#endif
#endif
//Start at beginning of the line
FCD_LCDDisplay0_Cursor (0, Line);
//Send out spaces to clear line
for (count = 0; count < rowcount; count++)
FCD_LCDDisplay0_RawSend(' ', 0x10);
//Move back to the beginning of the line.
FCD_LCDDisplay0_Cursor (0, Line);
}
void FCD_LCDDisplay0_RAM_Write(char nIdx, char d0, char d1, char d2, char d3, char d4, char d5, char d6, char d7)
{
//set CGRAM address
FCD_LCDDisplay0_RawSend(64 + (nIdx << 3), 0);
delay_ms(2);
//write CGRAM data
FCD_LCDDisplay0_RawSend(d0, 0x10);
FCD_LCDDisplay0_RawSend(d1, 0x10);
FCD_LCDDisplay0_RawSend(d2, 0x10);
FCD_LCDDisplay0_RawSend(d3, 0x10);
FCD_LCDDisplay0_RawSend(d4, 0x10);
FCD_LCDDisplay0_RawSend(d5, 0x10);
FCD_LCDDisplay0_RawSend(d6, 0x10);
FCD_LCDDisplay0_RawSend(d7, 0x10);
//Clear the display
FCD_LCDDisplay0_RawSend(0x01, 0);
delay_ms(2);
FCD_LCDDisplay0_RawSend(0x02, 0);
delay_ms(2);
}
//ADC0: //Macro implementations
void FCD_ADC0_SampleADC()
{
/*******Supported Devices******************************************************************
// 16F722, 16F723, 16F724, 16F726, 16F727, 16F1933, 16F1934, 16F1936, 16F1937, 16F1939
******************************************************************************************/
#define MX_ADC_CHANNEL 0
#define MX_ADC_SAMP_TIME 40
#define MX_ADC_CONV_SP 3
#define MX_ADC_VREF_OPT 0
//set up ADC conversion
char old_tris, cnt;
adcon1 = (MX_ADC_CONV_SP & 0x07) << 4;
//find appropriate bit
#if (MX_ADC_CHANNEL == 0)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 1)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 2)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 3)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x08
#define MX_ADC_ANSEL_REG ansela
#if (MX_ADC_VREF_OPT != 0)
#pragma error "Target device is currently using AN3 for VREF+"
#endif
#endif
#if (MX_ADC_CHANNEL == 4)
#define MX_ADC_TRIS_REG trisa
#define MX_ADC_TRIS_MSK 0x20
#define MX_ADC_ANSEL_REG ansela
#endif
#if (MX_ADC_CHANNEL == 5)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL == 6)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL == 7)
#define MX_ADC_TRIS_REG trise
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG ansele
#endif
#if (MX_ADC_CHANNEL ==

#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x04
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 9)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x08
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 10)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x02
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 11)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x10
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 12)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x01
#define MX_ADC_ANSEL_REG anselb
#endif
#if (MX_ADC_CHANNEL == 13)
#define MX_ADC_TRIS_REG trisb
#define MX_ADC_TRIS_MSK 0x20
#define MX_ADC_ANSEL_REG anselb
#endif
//sanity check
#ifndef MX_ADC_TRIS_REG
#pragma error "ADC Type 18 conversion code error - please contact technical support"
#endif
//assign VREF functionality
#if (MX_ADC_VREF_OPT != 0)
st_bit(adcon1, ADREF1);
#endif
//store old tris value, and set the i/o pin as an analogue input
old_tris = MX_ADC_TRIS_REG;
MX_ADC_TRIS_REG = MX_ADC_TRIS_REG | MX_ADC_TRIS_MSK;
MX_ADC_ANSEL_REG = MX_ADC_ANSEL_REG | MX_ADC_TRIS_MSK;
//turn ADC on
adcon0 = 0x01 | (MX_ADC_CHANNEL << 2);
//wait the acquisition time
cnt = 0;
while (cnt < MX_ADC_SAMP_TIME) cnt++;
//begin conversion and wait until it has finished
adcon0 = adcon0 | 0x02;
while (adcon0 & 0x02);
//restore old tris value, and reset adc registers
MX_ADC_TRIS_REG = old_tris;
MX_ADC_ANSEL_REG = 0x00;
adcon0 = 0x00;
#undef MX_ADC_TRIS_REG
#undef MX_ADC_TRIS_MSK
#undef MX_ADC_ANSEL_REG
#undef MX_ADC_SAMP_TIME
#undef MX_ADC_CHANNEL
#undef MX_ADC_CONV_SP
#undef MX_ADC_VREF_OPT
}
char FCD_ADC0_ReadAsByte()
{
FCD_ADC0_SampleADC();
#ifdef adres
return adres;
#else
return adresh;
#endif
}
short FCD_ADC0_ReadAsInt()
{
short iRetVal;
FCD_ADC0_SampleADC();
#ifdef adres
iRetVal = (adres << 2);
#else
iRetVal = (adresh << 2);
iRetVal = iRetVal | (adresl >> 6);
#endif
return (iRetVal);
}
float FCD_ADC0_ReadAsVoltage()
{
int iSample;
float fSample, fVoltage, fVperDiv;
#define MX_ADC_VREF_V 500
iSample = FCD_ADC0_ReadAsInt(); //Read as 10-bit Integer
#ifdef _BOOSTC
fVoltage = float32_from_int32(MX_ADC_VREF_V); //Convert reference voltage count to floating point (0 - 500 x 10mV)
fVoltage = float32_mul(fVoltage, 0.01); //Convert reference voltage count to actual voltage (0 - 5)
fVperDiv = float32_mul(fVoltage, 0.000976); //Convert actual voltage to voltage per division (VRef / 1024)
fSample = float32_from_int32(iSample); //Convert to floating point variable
fVoltage = float32_mul(fSample, fVperDiv); //Calculate floating point voltage
#endif
#ifdef HI_TECH_C
fVoltage = MX_ADC_VREF_V; //Convert reference voltage count to floating point (0 - 500 x 10mV)
fVoltage = fVoltage * 0.01; //Convert reference voltage count to actual voltage (0 - 5)
fVperDiv = fVoltage * 0.000976; //Convert actual voltage to voltage per division (VRef / 1024)
fSample = iSample; //Convert to floating point variable
fVoltage = fSample * fVperDiv; //Calculate floating point voltage
#endif
#undef MX_ADC_VREF_V
return (fVoltage);
}
void FCD_ADC0_ReadAsString(char* FCR_RETVAL, char FCR_RETVAL_SIZE)
{
float fVoltage;
fVoltage = FCD_ADC0_ReadAsVoltage();
FCI_FLOAT_TO_STRING(fVoltage, 2, FCR_RETVAL, FCR_RETVAL_SIZE); //Convert to String
}
//PWM0: //Macro implementations
void FCD_PWM0_Enable(char nIdx)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#else
#ifndef MX_PWM_CNT
#pragma error FCD file error (no MX_PWM_CNT)
#endif
#if (MX_PWM_CNT < 1)
#pragma error FCD file error (MX_PWM_CNT < 1)
#endif
#if (MX_PWM_CNT > 2)
#pragma error FCD file error (MX_PWM_CNT > 2)
#endif
#ifndef MX_PWM_TRIS1
#pragma error FCD file error (no MX_PWM_TRIS1)
#endif
#ifndef MX_PWM_1
#pragma error FCD file error (no MX_PWM_1)
#endif
#if (MX_PWM_CNT == 2)
#ifndef MX_PWM_TRIS2
#pragma error FCD file error (no MX_PWM_TRIS2)
#endif
#ifndef MX_PWM_2
#pragma error FCD file error (no MX_PWM_2)
#endif
#endif
#if (0 == 1)
#ifndef MX_PWM_TRIS1a
#pragma error PWM component error (using alternative, but no MX_PWM_TRIS1a)
#define MX_PWM_ALT_ERROR
#endif
#ifndef MX_PWM_1a
#pragma error PWM component error (using alternative, but no MX_PWM_1a)
#define MX_PWM_ALT_ERROR
#endif
#endif
#if (0 == 2)
#ifndef MX_PWM_TRIS2a
#pragma error PWM component error (using alternative, but no MX_PWM_TRIS2a)
#define MX_PWM_ALT_ERROR
#endif
#ifndef MX_PWM_2a
#pragma error PWM component error (using alternative, but no MX_PWM_2a)
#define MX_PWM_ALT_ERROR
#endif
#endif
#endif
#ifdef MX_PWM
pr2 = 90;
t2con = 0x05;
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccp1con = 0x0C;
#if (0 == 1)
#ifndef MX_PWM_ALT_ERROR
clear_bit(MX_PWM_TRIS1a, MX_PWM_1a);
#endif
#else
clear_bit(MX_PWM_TRIS1, MX_PWM_1);
#endif
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccp2con = 0x0C;
#if (0 == 2)
#ifndef MX_PWM_ALT_ERROR
clear_bit(MX_PWM_TRIS2a, MX_PWM_2a);
#endif
#else
clear_bit(MX_PWM_TRIS2, MX_PWM_2);
#endif
}
#endif
#endif
#ifdef MX_PWM_ALT_ERROR
#undef MX_PWM_ALT_ERROR
#endif
}
void FCD_PWM0_Disable(char nIdx)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccp1con = 0x00;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccp2con = 0x00;
}
#endif
#endif
}
void FCD_PWM0_SetDutyCycle(char nIdx, char nDuty)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccpr1l = nDuty;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccpr2l = nDuty;
}
#endif
#endif
}
void FCD_PWM0_ChangePeriod(char nPeriodVal, char nPrescalerVal)
{
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
pr2 = nPeriodVal;
switch (nPrescalerVal)
{
case 1:
t2con = 0x04;
break;
case 4:
t2con = 0x05;
break;
case 16:
t2con = 0x06;
break;
}
#endif
}
void FCD_PWM0_SetDutyCycle10bit(char nIdx, short nDuty)
{
char nCCPxCONtemp;
//error checking
#ifndef MX_PWM
#warning "This chip does not have PWM capability"
#endif
#ifdef MX_PWM
#if (MX_PWM_CNT >= 1)
if (nIdx == 1)
{
ccpr1l = (nDuty & 0x3FC) >> 2;
nDuty = (nDuty & 0x03) << 4;
nCCPxCONtemp = (ccp1con & 0xCF) | nDuty;
ccp1con = nCCPxCONtemp;
}
#endif
#if (MX_PWM_CNT >= 2)
if (nIdx == 2)
{
ccpr2l = (nDuty & 0x3FC) >> 2;
nDuty = (nDuty & 0x03) << 4;
nCCPxCONtemp = (ccp2con & 0xCF) | nDuty;
ccp2con = nCCPxCONtemp;
}
#endif
#endif
}
//Macro implementations
void main()
{
//Initialisation
ansela = 0x00;
anselb = 0x00;
//Interrupt initialisation code
option_reg = 0xC0;
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Start
FCD_LCDDisplay0_Start();
//Call Component Macro
//Call Component Macro: PWM(0)::Enable(1)
FCD_PWM0_Enable(1);
//Call Component Macro
//Call Component Macro: PWM(0)::Enable(2)
FCD_PWM0_Enable(2);
//Loop
//Loop: While 1
while (1)
{
//Output
//Output: 1 -> C3
trisc = trisc & 0xf7;
if (1)
portc = (portc & 0xf7) | 0x08;
else
portc = portc & 0xf7;
//Call Component Macro
//Call Component Macro: PWM(0)::SetDutyCycle(1, tec)
FCD_PWM0_SetDutyCycle(1, FCV_TEC);
//Call Component Macro
//Call Component Macro: PWM(0)::SetDutyCycle(2, fan)
FCD_PWM0_SetDutyCycle(2, FCV_FAN);
//Call Component Macro
//Call Component Macro: coldplate=ADC(0)::ReadAsByte
FCV_COLDPLATE = FCD_ADC0_ReadAsByte();
//Delay
//Delay: 250 ms
delay_ms(250);
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintNumber(coldplate)
FCD_LCDDisplay0_PrintNumber(FCV_COLDPLATE);
//Decision
//Decision: coldplate< 211?
if (FCV_COLDPLATE< 211)
{
//Calculation
//Calculation:
// tec = 91
// fan = 91
FCV_TEC = 91;
FCV_FAN = 91;
}
//Decision
//Decision: coldplate>211?
if (FCV_COLDPLATE>211)
{
//Decision
//Decision: coldplate>221?
if (FCV_COLDPLATE>221)
{
//Calculation
//Calculation:
// tec = 0
// fan = 0
FCV_TEC = 0;
FCV_FAN = 0;
} else {
//Calculation
//Calculation:
// tec = 91
// fan = 30
FCV_TEC = 91;
FCV_FAN = 30;
}
}
//Delay
//Delay: 1 s
delay_s(1);
}
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}