//************************************************************************************
//**
//** File name: C:\Documents and Settings\kox\Bureau\pl7\ARERVOIR forum.c
//** Generated by: Flowcode v4.3.7.63
//** Date: Monday, June 13, 2011 21:33:38
//** Licence: Professional
//** Registered to: 20ACM8
//**
//**
//**
http://www.matrixmultimedia.com
//************************************************************************************
#define MX_PIC
//Définir pour microcontrôleur
#define P16F677
#define MX_EE
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_BCB
#define MX_SPI_SDI 4
#define MX_SPI_SDO 7
#define MX_SPI_SCK 6
#define MX_I2C
#define MX_MI2C
#define MX_I2C_B
#define MX_I2C_SDA 4
#define MX_I2C_SCL 6
//Fonctions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Données de Configuration
//Fonctions internes
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Déclarations de fonction Macro
//Déclarations de Variable
#define FCSZ_INPUT_STRING 16
char FCV_INCREMENTSTEP;
char FCV_INPUT_STRING[FCSZ_INPUT_STRING];
char FCV_KEY;
short FCV_IN1;
char FCV_DECREMENTSTEP;
//Defines:
/**** Macro Substitutions ****
portb = Switch Port Register
trisb = Switch Data Direction Register
7 = Switch Pin
0 = Switch Polarity Control
0 = Switch Debounce Delay Value
******************************/
//SWITCH(0): //Déclarations de fonction Macro
char FCD_SWITCH0_ReadState();
void FCD_SWITCH0_WaitUntilHigh();
void FCD_SWITCH0_WaitUntilLow();
//Defines:
/**** Macro Substitutions ****
portc = D1 Port
trisc = D1 Data Direction
portc = D2 Port
trisc = D2 Data Direction
portc = D3 Port
trisc = D3 Data Direction
portc = D4 Port
trisc = D4 Data Direction
portc = RS Port
trisc = RS Data Direction
portc = E Port
trisc = 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_132806 = Unique Component Reference Number
4 = Row Count
20 = Column Count
******************************/
//component connections
#define LCD_132806_PORT0 portc
#define LCD_132806_TRIS0 trisc
#define LCD_132806_PORT1 portc
#define LCD_132806_TRIS1 trisc
#define LCD_132806_PORT2 portc
#define LCD_132806_TRIS2 trisc
#define LCD_132806_PORT3 portc
#define LCD_132806_TRIS3 trisc
#define LCD_132806_PORT4 portc
#define LCD_132806_TRIS4 trisc
#define LCD_132806_PORT5 portc
#define LCD_132806_TRIS5 trisc
#define LCD_132806_BIT0 0
#define LCD_132806_BIT1 1
#define LCD_132806_BIT2 2
#define LCD_132806_BIT3 3
#define LCD_132806_RS 4
#define LCD_132806_E 5
#define LCD_132806_ROWCNT 4
#define LCD_132806_COLCNT 20
#ifdef _BOOSTC
#define LCD_132806_DELAY delay_10us(10)
#endif
#ifdef _C2C_
#define LCD_132806_DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_132806_DELAY __delay_us(120)
#endif
#ifndef LCD_132806_DELAY
#define LCD_132806_DELAY delay_us(100)
#endif
//LCDDisplay(0): //Déclarations de fonction Macro
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 ****
porta = Coil 1 Port Register
trisa = Coil 1 Data Direction Register
0 = Coil 1 Pin
porta = Coil 2 Port Register
trisa = Coil 2 Data Direction Register
1 = Coil 2 Pin
porta = Coil 3 Port Register
trisa = Coil 3 Data Direction Register
2 = Coil 3 Pin
porta = Coil 4 Port Register
trisa = Coil 4 Data Direction Register
3 = Coil 4 Pin
2 = Step Type - 0 = half step, 1 = full step (2-2), 2 = wave (1-1)
1 = Motor Type - 0 = bipolar/unipolar +ve, 1 = unipolar -ve
0 = Number of Full Steps Per Revolution
0 = Unused
Stepper_198314 = Unique Component Identifier
******************************/
//common defines
#define MX_Stepper_198314_PORT1 porta //0
#define MX_Stepper_198314_TRIS1 trisa
#define MX_Stepper_198314_PIN1 0
#define MX_Stepper_198314_PORT2 porta //1
#define MX_Stepper_198314_TRIS2 trisa
#define MX_Stepper_198314_PIN2 1
#define MX_Stepper_198314_PORT3 porta //2
#define MX_Stepper_198314_TRIS3 trisa
#define MX_Stepper_198314_PIN3 2
#define MX_Stepper_198314_PORT4 porta //3
#define MX_Stepper_198314_TRIS4 trisa
#define MX_Stepper_198314_PIN4 3
#define MX_Stepper_198314_STEP_TYPE 2 //0 = half step, 1 = full step (2-2), 2 = wave (1-1)
#define MX_Stepper_198314_WINDING_TYPE 1 //0 = bipolar/unipolar +ve, 1 = unipolar -ve
#if (MX_Stepper_198314_WINDING_TYPE == 2)
char Stepper_198314_pattern[8] = {0x06, 0x0e, 0x0a, 0x0b, 0x09, 0x0d, 0x05, 0x07};
#else
char Stepper_198314_pattern[8] = {0x09, 0x01, 0x05, 0x04, 0x06, 0x02, 0x0a, 0x08};
#endif
#if (MX_Stepper_198314_STEP_TYPE == 0)
#define MX_Stepper_198314_INC_STEP 1
#else
#define MX_Stepper_198314_INC_STEP 2
#endif
char Stepper_198314_phase = 0;
char Stepper_198314_enabled = 0;
//Stepper(0): //Déclarations de fonction Macro
void FCD_Stepper0_IncrementStep();
void FCD_Stepper0_DecrementStep();
void FCD_Stepper0_EnableMotor();
void FCD_Stepper0_DisableMotor();
//Defines:
/**** Macro Substitutions ****
{'1','4','7','*','2','5','8','0','3','6','9','#'} = Key List (Numbers)
{1,4,7,10,2,5,8,0,3,6,9,11} = Key List (Characters)
trisb = Row Data Direction Register
portb = Row Port Register
3 = Number Of Columns
4 = Number Of Rows
trisb = Column Data Direction Register
portb = Column Port Register
1 = Column 1 mask
2 = Column 2 mask
4 = Column 3 mask
16 = Column 4 mask
16 = Row 1 mask
32 = Row 2 mask
64 = Row 3 mask
128 = Row 4 mask
******************************/
//KeyPad(0): //Déclarations de fonction Macro
char FCD_KeyPad0_GetKeypadNumber();
char FCD_KeyPad0_GetKeypadAscii();
//SWITCH(0): //Implémentations Macro
char FCD_SWITCH0_ReadState()
{
char switchval;
#ifdef MX_10F_TRIS
tvar = tvar | (1 << 7);
asm("movf(_tvar),w");
asm("tris 6");
#else
set_bit ( trisb, 7 ); //Convert pin to input
#endif
delay_us(2); //Allow input voltage to settle
if (test_bit( portb, 7 )) //Read state on input
switchval = 1;
else
switchval = 0;
if ( 0 == 1 ) //Active low polarity
{
if (switchval) //Invert logic
switchval = 0;
else
switchval = 1;
}
return (switchval); //Return state of switch as least significant bit
}
void FCD_SWITCH0_WaitUntilHigh()
{
#ifdef MX_10F_TRIS
tvar = tvar | (1 << 7);
asm("movf(_tvar),w");
asm("tris 6");
#else
set_bit ( trisb, 7 ); //Convert pin to input
#endif
delay_us(2); //Allow input voltage to settle
if ( 0 == 0 ) //Active high polarity
{
while (test_bit( portb, 7 ) == 0); //Wait for pin to go high
}
else //Active low polarity
{
while (test_bit( portb, 7 )); //Wait for pin to go low
}
if ( 0 ) //Timeout specified?
Wdt_Delay_Ms(0);
}
void FCD_SWITCH0_WaitUntilLow()
{
#ifdef MX_10F_TRIS
tvar = tvar | (1 << 7);
asm("movf(_tvar),w");
asm("tris 6");
#else
set_bit ( trisb, 7 ); //Convert pin to input
#endif
delay_us(2); //Allow input voltage to settle
if ( 0 == 0 ) //Active high polarity
{
while (test_bit( portb, 7 )); //Wait for pin to go low
}
else //Active low polarity
{
while (test_bit( portb, 7 ) == 0); //Wait for pin to go high
}
if ( 0 ) //Timeout specified?
Wdt_Delay_Ms(0);
}
//LCDDisplay(0): //Implémentations Macro
void FCD_LCDDisplay0_RawSend(char in, char mask)
{
unsigned char pt;
clear_bit(LCD_132806_PORT0, LCD_132806_BIT0);
clear_bit(LCD_132806_PORT1, LCD_132806_BIT1);
clear_bit(LCD_132806_PORT2, LCD_132806_BIT2);
clear_bit(LCD_132806_PORT3, LCD_132806_BIT3);
clear_bit(LCD_132806_PORT4, LCD_132806_RS);
clear_bit(LCD_132806_PORT5, LCD_132806_E);
pt = ((in >> 4) & 0x0f);
if (pt & 0x01)
set_bit(LCD_132806_PORT0, LCD_132806_BIT0);
if (pt & 0x02)
set_bit(LCD_132806_PORT1, LCD_132806_BIT1);
if (pt & 0x04)
set_bit(LCD_132806_PORT2, LCD_132806_BIT2);
if (pt & 0x08)
set_bit(LCD_132806_PORT3, LCD_132806_BIT3);
if (mask)
set_bit(LCD_132806_PORT4, LCD_132806_RS);
LCD_132806_DELAY;
set_bit (LCD_132806_PORT5, LCD_132806_E);
LCD_132806_DELAY;
clear_bit (LCD_132806_PORT5, LCD_132806_E);
pt = (in & 0x0f);
LCD_132806_DELAY;
clear_bit(LCD_132806_PORT0, LCD_132806_BIT0);
clear_bit(LCD_132806_PORT1, LCD_132806_BIT1);
clear_bit(LCD_132806_PORT2, LCD_132806_BIT2);
clear_bit(LCD_132806_PORT3, LCD_132806_BIT3);
clear_bit(LCD_132806_PORT4, LCD_132806_RS);
clear_bit(LCD_132806_PORT5, LCD_132806_E);
if (pt & 0x01)
set_bit(LCD_132806_PORT0, LCD_132806_BIT0);
if (pt & 0x02)
set_bit(LCD_132806_PORT1, LCD_132806_BIT1);
if (pt & 0x04)
set_bit(LCD_132806_PORT2, LCD_132806_BIT2);
if (pt & 0x08)
set_bit(LCD_132806_PORT3, LCD_132806_BIT3);
if (mask)
set_bit(LCD_132806_PORT4, LCD_132806_RS);
LCD_132806_DELAY;
set_bit (LCD_132806_PORT5, LCD_132806_E);
LCD_132806_DELAY;
clear_bit (LCD_132806_PORT5, LCD_132806_E);
LCD_132806_DELAY;
}
void FCD_LCDDisplay0_Start()
{
clear_bit(LCD_132806_TRIS0, LCD_132806_BIT0);
clear_bit(LCD_132806_TRIS1, LCD_132806_BIT1);
clear_bit(LCD_132806_TRIS2, LCD_132806_BIT2);
clear_bit(LCD_132806_TRIS3, LCD_132806_BIT3);
clear_bit(LCD_132806_TRIS4, LCD_132806_RS);
clear_bit(LCD_132806_TRIS5, LCD_132806_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_132806_ROWCNT == 1)
y=0x80;
#endif
#if (LCD_132806_ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
#endif
#if (LCD_132806_ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;
#if (LCD_132806_COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif
#if (LCD_132806_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_132806_ROWCNT == 1)
rowcount=80;
#endif
#if (LCD_132806_ROWCNT == 2)
rowcount=40;
#endif
#if (LCD_132806_ROWCNT == 4)
#if (LCD_132806_COLCNT == 16)
rowcount=16;
#endif
#if (LCD_132806_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);
}
//Stepper(0): //Implémentations Macro
void FCD_Stepper0_IncrementStep()
{
char pattern_now;
if( Stepper_198314_enabled)
{
Stepper_198314_phase = (Stepper_198314_phase + MX_Stepper_198314_INC_STEP); //increment step
#if (MX_Stepper_198314_STEP_TYPE == 1)
Stepper_198314_phase &=0x06; //full step, even index
#endif
#if (MX_Stepper_198314_STEP_TYPE == 2) //full step, odd index
Stepper_198314_phase |=0x01;
#endif
Stepper_198314_phase &= 0x07;
pattern_now = Stepper_198314_pattern[Stepper_198314_phase];
if(test_bit(pattern_now, 0)) set_bit (MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
else clear_bit (MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
if(test_bit(pattern_now, 1)) set_bit (MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
else clear_bit (MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
if(test_bit(pattern_now, 2)) set_bit (MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
else clear_bit (MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
if(test_bit(pattern_now, 3)) set_bit (MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
else clear_bit (MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
}
}
void FCD_Stepper0_DecrementStep()
{
char pattern_now;
if( Stepper_198314_enabled)
{
Stepper_198314_phase = (Stepper_198314_phase - MX_Stepper_198314_INC_STEP); //increment step
#if (MX_Stepper_198314_STEP_TYPE == 1)
Stepper_198314_phase &=0x06; //full step, even index
#endif
#if (MX_Stepper_198314_STEP_TYPE == 2) //full step, odd index
Stepper_198314_phase |=0x01;
#endif
Stepper_198314_phase &= 0x07;
pattern_now = Stepper_198314_pattern[Stepper_198314_phase];
if(test_bit(pattern_now, 0)) set_bit (MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
else clear_bit (MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
if(test_bit(pattern_now, 1)) set_bit (MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
else clear_bit (MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
if(test_bit(pattern_now, 2)) set_bit (MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
else clear_bit (MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
if(test_bit(pattern_now, 3)) set_bit (MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
else clear_bit (MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
}
}
void FCD_Stepper0_EnableMotor()
{
Stepper_198314_enabled = 1;
clear_bit(MX_Stepper_198314_TRIS1, MX_Stepper_198314_PIN1);
clear_bit(MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
clear_bit(MX_Stepper_198314_TRIS2, MX_Stepper_198314_PIN2);
clear_bit(MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
clear_bit(MX_Stepper_198314_TRIS3, MX_Stepper_198314_PIN3);
clear_bit(MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
clear_bit(MX_Stepper_198314_TRIS4, MX_Stepper_198314_PIN4);
clear_bit(MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
}
void FCD_Stepper0_DisableMotor()
{
Stepper_198314_enabled = 0;
set_bit(MX_Stepper_198314_TRIS1, MX_Stepper_198314_PIN1);
clear_bit(MX_Stepper_198314_PORT1, MX_Stepper_198314_PIN1);
set_bit(MX_Stepper_198314_TRIS2, MX_Stepper_198314_PIN2);
clear_bit(MX_Stepper_198314_PORT2, MX_Stepper_198314_PIN2);
set_bit(MX_Stepper_198314_TRIS3, MX_Stepper_198314_PIN3);
clear_bit(MX_Stepper_198314_PORT3, MX_Stepper_198314_PIN3);
set_bit(MX_Stepper_198314_TRIS4, MX_Stepper_198314_PIN4);
clear_bit(MX_Stepper_198314_PORT4, MX_Stepper_198314_PIN4);
}
//KeyPad(0): //Implémentations Macro
char FCD_KeyPad0_GetKeypadNumber()
{
//get matrices for rows and columns
#if (3 == 1)
#define KPAD_COL_MTX {1}
#define KPAD_COL_MASK (1)
#endif
#if (3 == 2)
#define KPAD_COL_MTX {1,2}
#define KPAD_COL_MASK (1|2)
#endif
#if (3 == 3)
#define KPAD_COL_MTX {1,2,4}
#define KPAD_COL_MASK (1|2|4)
#endif
#if (3 == 4)
#define KPAD_COL_MTX {1,2,4,16}
#define KPAD_COL_MASK (1|2|4|16)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {16}
#define KPAD_ROW_MASK (16)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {16,32}
#define KPAD_ROW_MASK (16|32)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {16,32,64}
#define KPAD_ROW_MASK (16|32|64)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {16,32,64,128}
#define KPAD_ROW_MASK (16|32|64|128)
#endif
#ifndef KPAD_COL_MTX
#ifdef _BOOSTC
#pragma error "Keypad error: column count is not 1-4"
#endif
#ifdef HI_TECH_C
#error Keypad error: column count is not 1-4
#endif
#endif
#ifndef KPAD_ROW_MTX
#ifdef _BOOSTC
#pragma error "Keypad error: row count is not 1-4"
#endif
#ifdef HI_TECH_C
#error Keypad error: row count is not 1-4
#endif
#endif
//store keys and pin connections into a constant array
#ifdef _BOOSTC
rom char* mtxKeysAsNumbers = {1,4,7,10,2,5,8,0,3,6,9,11};
rom char* mtxCols = KPAD_COL_MTX;
rom char* mtxRows = KPAD_ROW_MTX;
#endif
#ifdef HI_TECH_C
const char mtxKeysAsNumbers[] = {1,4,7,10,2,5,8,0,3,6,9,11};
const char mtxCols[] = KPAD_COL_MTX;
const char mtxRows[] = KPAD_ROW_MTX;
#endif
//set up i/o of port (rows = inputs, columns = outputs)
trisb = (trisb | KPAD_ROW_MASK);
trisb = (trisb & ~KPAD_COL_MASK); //BR
char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portb = mtxCols[iCol];
//delay
delay_us(10);
//read the port
c_ip = portb;
//check for a hit
for (iRow=0; iRow<4; iRow++)
{
if ((c_ip & mtxRows[iRow]) != 0)
{
//found it!
goto found_key;
}
}
}
//if it gets here, it has not been found...
return (255);
found_key:
return (mtxKeysAsNumbers[(iCol*4) + iRow]);
#undef KPAD_COL_MTX
#undef KPAD_ROW_MTX
#undef KPAD_COL_MASK
#undef KPAD_ROW_MASK
}
char FCD_KeyPad0_GetKeypadAscii()
{
//get matrices for rows and columns
#if (3 == 1)
#define KPAD_COL_MTX {1}
#define KPAD_COL_MASK (1)
#endif
#if (3 == 2)
#define KPAD_COL_MTX {1,2}
#define KPAD_COL_MASK (1|2)
#endif
#if (3 == 3)
#define KPAD_COL_MTX {1,2,4}
#define KPAD_COL_MASK (1|2|4)
#endif
#if (3 == 4)
#define KPAD_COL_MTX {1,2,4,16}
#define KPAD_COL_MASK (1|2|4|16)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {16}
#define KPAD_ROW_MASK (16)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {16,32}
#define KPAD_ROW_MASK (16|32)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {16,32,64}
#define KPAD_ROW_MASK (16|32|64)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {16,32,64,128}
#define KPAD_ROW_MASK (16|32|64|128)
#endif
#ifndef KPAD_COL_MTX
#ifdef _BOOSTC
#pragma error "Keypad error: column count is not 1-4"
#endif
#ifdef HI_TECH_C
#error Keypad error: column count is not 1-4
#endif
#endif
#ifndef KPAD_ROW_MTX
#ifdef _BOOSTC
#pragma error "Keypad error: row count is not 1-4"
#endif
#ifdef HI_TECH_C
#error Keypad error: row count is not 1-4
#endif
#endif
//store keys and pin connections into a constant array
#ifdef _BOOSTC
rom char* mtxKeysAsChars = {'1','4','7','*','2','5','8','0','3','6','9','#'};
rom char* mtxCols = KPAD_COL_MTX;
rom char* mtxRows = KPAD_ROW_MTX;
#endif
#ifdef HI_TECH_C
const char mtxKeysAsChars[] = {'1','4','7','*','2','5','8','0','3','6','9','#'};
const char mtxCols[] = KPAD_COL_MTX;
const char mtxRows[] = KPAD_ROW_MTX;
#endif
//set up i/o of port (rows = inputs, columns = outputs)
trisb = (trisb | KPAD_ROW_MASK);
trisb = (trisb & ~KPAD_COL_MASK);
char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portb = mtxCols[iCol];
//delay
delay_us(10);
//read the port
c_ip = portb;
//check for a hit
for (iRow=0; iRow<4; iRow++)
{
if ((c_ip & mtxRows[iRow]) != 0)
{
//found it!
goto found_key;
}
}
}
//if it gets here, it has not been found...
return (255);
found_key:
return (mtxKeysAsChars[(iCol*4) + iRow]);
#undef KPAD_COL_MTX
#undef KPAD_ROW_MTX
#undef KPAD_COL_MASK
#undef KPAD_ROW_MASK
}
//Implémentations Macro
void main()
{
//Initialisation
ansel = 0;
anselh = 0;
//Code d'initialisation d'Interruption
option_reg = 0xC0;
//Appel de la Routine Composant
//Appel de la Routine Composant: LCDDisplay(0)::Init
FCD_LCDDisplay0_Start();
//Boucle
//Boucle: Tant que 1
while (1)
{
//GetKeypadAscii
//Appel de la Routine Composant: key=KeyPad(0)::GetKeypadAscii
FCV_KEY = FCD_KeyPad0_GetKeypadAscii();
//if dualed <255
//Décision: key<255?
if (FCV_KEY<255)
{
//manupilation string
//Manipulation de Chaîne de caractères:
// Input_string = Input_string + key
FCI_CONCATENATE(FCV_INPUT_STRING,FCSZ_INPUT_STRING,(char*)&FCV_KEY,1,FCV_INPUT_STRING,FCSZ_INPUT_STRING);
}
//curseur
//Appel de la Routine Composant: LCDDisplay(0)::Curseur(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);
//Output string so far
//Appel de la Routine Composant: LCDDisplay(0)::Écrit_Chaîne(Input_string)
FCD_LCDDisplay0_PrintString(FCV_INPUT_STRING,FCSZ_INPUT_STRING);
//While switch held down
//Boucle: Tant que key < 255
while (FCV_KEY < 255)
{
//get keypad number
//Appel de la Routine Composant: key=KeyPad(0)::GetKeypadNumber
FCV_KEY = FCD_KeyPad0_GetKeypadNumber();
}
//Call Component Macro
//Appel de la Routine Composant: key=KeyPad(0)::GetKeypadNumber
FCV_KEY = FCD_KeyPad0_GetKeypadNumber();
//Reset LCD Cursor
//Appel de la Routine Composant: LCDDisplay(0)::Curseur(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);
//Output string so far
//Appel de la Routine Composant: LCDDisplay(0)::Écrit_Chaîne(Input_string)
FCD_LCDDisplay0_PrintString(FCV_INPUT_STRING,FCSZ_INPUT_STRING);
//While switch held down
//Boucle: Tant que key < 255
while (FCV_KEY < 255)
{
//Call Component Macro
//Appel de la Routine Composant: key=KeyPad(0)::GetKeypadAscii
FCV_KEY = FCD_KeyPad0_GetKeypadAscii();
}
//system off if switch
//Entrée: B7 -> IN1
trisb = trisb | 0x80;
FCV_IN1 = ((portb & 0x80) == 0x80);
//Appel de la Routine Composant
//Appel de la Routine Composant: IN1=SWITCH(0)::Lire_État
FCV_IN1 = FCD_SWITCH0_ReadState();
//Décision
//Décision: IN1?
if (FCV_IN1)
{
} else {
//Point de Jonction
//Point de Jonction: [A]: A
FCC_Principal_A:
;
//Clear LCD
//Appel de la Routine Composant: LCDDisplay(0)::Effacer
FCD_LCDDisplay0_Clear();
//Move to second line of LCD
//Appel de la Routine Composant: LCDDisplay(0)::Curseur(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);
//Print Input String
//Appel de la Routine Composant: LCDDisplay(0)::Écrit_Chaîne(Input_string)
FCD_LCDDisplay0_PrintString(FCV_INPUT_STRING,FCSZ_INPUT_STRING);
//Appel de la Routine Composant
//Appel de la Routine Composant: Stepper(0)::EnableMotor
FCD_Stepper0_EnableMotor();
//Appel de la Routine Composant
//Appel de la Routine Composant: Stepper(0)::IncrementStep
FCD_Stepper0_IncrementStep();
//Calcul
//Calcul:
// IncrementStep = IncrementStep+1
FCV_INCREMENTSTEP = FCV_INCREMENTSTEP+1;
//Appel de la Routine Composant
//Appel de la Routine Composant: LCDDisplay(0)::Curseur(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);
//Appel de la Routine Composant
//Appel de la Routine Composant: LCDDisplay(0)::Écrit_Nombre(IncrementStep)
FCD_LCDDisplay0_PrintNumber(FCV_INCREMENTSTEP);
//compare dualed with incrementstep
//Décision: IncrementStep=Input_string[16]?
if (FCV_INCREMENTSTEP==FCV_INPUT_STRING[16])
{
//stepper off
//Appel de la Routine Composant: Stepper(0):
isableMotor
FCD_Stepper0_DisableMotor();
//Aller au Point de Jonction
//Aller au Point de Jonction: [A]: A
goto FCC_Principal_A;
}
}
}
//Aller au Point de Jonction
//Aller au Point de Jonction: [A]: A
goto FCC_Principal_A;
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}