C ASM PROGRAMING

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
ivan sandler
Posts: 4
Joined: Tue Aug 31, 2010 11:54 am
Been thanked: 1 time
Contact:

C ASM PROGRAMING

Post by ivan sandler »

STEVE
THANK YOU FOR ANSWERING ME BACK BELOW IS THE FLOW CODE C SOFTWARE.
NOW I DID THE PROGRAMING IN FLOWCODE 4 AND WHEN I TRIED TO COMPILE IT TO ASM OR TO HEX IT GAVE ME 2 ERRORS


AS I STATED ALREADY IT WORK PERFECTLY ON THE SIMULATOR

REGARDS

IVAN

PS: I DO NOT KNOW HOW TO ATTACHE THE FLOWCODE FILE SO IF YOU SEND ME A EMAIL ADDRESS I CAN SEND IT TO YOU



THIS IS THE MESSAGE I GOT BELOW
***********************************************************************************************************************************************
http://www.matrixmultimedia.com


Launching the compiler...
C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic16.flowcode.exe -v -t PIC16F877A "YOU TUBE DIGITAL LOCK.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

Single user Lite License (Unregistered) for 0 node(s)
Limitations: PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only


YOU TUBE DIGITAL LOCK.c
Starting preprocessor: C:\PROGRA~1\MATRIX~1\FLOWCO~1\BoostC\pp.exe "C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.c" -i C:\PROGRA~1\MATRIX~1\FLOWCO~1\BoostC\include -d _PIC16F877A -la -c2 -o "C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.pp" -v -d _BOOSTC -d _PIC16


........

C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.c(246): error: missing semicolon
C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.c(181): error: failure

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


//************************************************************************************
//**
//** File name: C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.c
//** Generated by: Flowcode v4.3.7.63
//** Date: Tuesday, August 31, 2010 20:03:55
//** Licence: Professional
//** Registered to: ivan sandler
//**
//**
//** http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P16F877A
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#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

//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
void FCM_TESTCODE();
void FCM_CORRECT_CODE();
void FCM_WRONG_CODE();


//Variable declarations
char FCV_KEYPADNUMBER;
char FCV_DIGIT1;
char FCV_DIGIT2;

char FCLV_LOOP1;

//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)
tris` = Row Data Direction Register
port` = Row Port Register
3 = Number Of Columns
4 = Number Of Rows
trisc = Column Data Direction Register
portc = Column Port Register
1 = Column 1 mask
2 = Column 2 mask
4 = Column 3 mask
1 = Column 4 mask
1 = Row 1 mask
1 = Row 2 mask
1 = Row 3 mask
1 = Row 4 mask
******************************/




//KeyPad(0): //Macro function declarations

char FCD_KeyPad0_GetKeypadNumber();
char FCD_KeyPad0_GetKeypadAscii();
//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_1114936 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/

//component connections
#define LCD_1114936_PORT0 portb
#define LCD_1114936_TRIS0 trisb
#define LCD_1114936_PORT1 portb
#define LCD_1114936_TRIS1 trisb
#define LCD_1114936_PORT2 portb
#define LCD_1114936_TRIS2 trisb
#define LCD_1114936_PORT3 portb
#define LCD_1114936_TRIS3 trisb
#define LCD_1114936_PORT4 portb
#define LCD_1114936_TRIS4 trisb
#define LCD_1114936_PORT5 portb
#define LCD_1114936_TRIS5 trisb
#define LCD_1114936_BIT0 0
#define LCD_1114936_BIT1 1
#define LCD_1114936_BIT2 2
#define LCD_1114936_BIT3 3
#define LCD_1114936_RS 4
#define LCD_1114936_E 5
#define LCD_1114936_ROWCNT 2
#define LCD_1114936_COLCNT 16

#ifdef _BOOSTC
#define LCD_1114936_DELAY delay_10us(10)
#endif
#ifdef _C2C_
#define LCD_1114936_DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_1114936_DELAY __delay_us(120)
#endif
#ifndef LCD_1114936_DELAY
#define LCD_1114936_DELAY delay_us(100)
#endif




//LCDDisplay(0): //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);



//KeyPad(0): //Macro implementations


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,1}
#define KPAD_COL_MASK (1|2|4|1)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {1}
#define KPAD_ROW_MASK (1)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {1,1}
#define KPAD_ROW_MASK (1|1)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {1,1,1}
#define KPAD_ROW_MASK (1|1|1)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {1,1,1,1}
#define KPAD_ROW_MASK (1|1|1|1)
#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)
tris` = (tris` | KPAD_ROW_MASK);
trisc = (trisc & ~KPAD_COL_MASK); //BR

char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portc = mtxCols[iCol];

//delay
delay_us(10);

//read the port
c_ip = port`;

//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,1}
#define KPAD_COL_MASK (1|2|4|1)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {1}
#define KPAD_ROW_MASK (1)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {1,1}
#define KPAD_ROW_MASK (1|1)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {1,1,1}
#define KPAD_ROW_MASK (1|1|1)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {1,1,1,1}
#define KPAD_ROW_MASK (1|1|1|1)
#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)
tris` = (tris` | KPAD_ROW_MASK);
trisc = (trisc & ~KPAD_COL_MASK);

char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portc = mtxCols[iCol];

//delay
delay_us(10);

//read the port
c_ip = port`;

//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

}



//LCDDisplay(0): //Macro implementations


void FCD_LCDDisplay0_RawSend(char in, char mask)
{
unsigned char pt;

clear_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_PORT4, LCD_1114936_RS);
clear_bit(LCD_1114936_PORT5, LCD_1114936_E);
pt = ((in >> 4) & 0x0f);
if (pt & 0x01)
set_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
if (pt & 0x02)
set_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
if (pt & 0x04)
set_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
if (pt & 0x08)
set_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
if (mask)
set_bit(LCD_1114936_PORT4, LCD_1114936_RS);
LCD_1114936_DELAY;
set_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
clear_bit (LCD_1114936_PORT5, LCD_1114936_E);
pt = (in & 0x0f);
LCD_1114936_DELAY;
clear_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_PORT4, LCD_1114936_RS);
clear_bit(LCD_1114936_PORT5, LCD_1114936_E);
if (pt & 0x01)
set_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
if (pt & 0x02)
set_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
if (pt & 0x04)
set_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
if (pt & 0x08)
set_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
if (mask)
set_bit(LCD_1114936_PORT4, LCD_1114936_RS);
LCD_1114936_DELAY;
set_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
clear_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
}

void FCD_LCDDisplay0_Start()
{

clear_bit(LCD_1114936_TRIS0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_TRIS1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_TRIS2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_TRIS3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_TRIS4, LCD_1114936_RS);
clear_bit(LCD_1114936_TRIS5, LCD_1114936_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_1114936_ROWCNT == 1)
y=0x80;
#endif

#if (LCD_1114936_ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
#endif

#if (LCD_1114936_ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;

#if (LCD_1114936_COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif

#if (LCD_1114936_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_1114936_ROWCNT == 1)
rowcount=80;
#endif

#if (LCD_1114936_ROWCNT == 2)
rowcount=40;
#endif

#if (LCD_1114936_ROWCNT == 4)
#if (LCD_1114936_COLCNT == 16)
rowcount=16;
#endif
#if (LCD_1114936_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);
}

//Macro implementations

void FCM_TESTCODE()
{

//FIRST NUMBER
//Decision: DIGIT1=8?
if (FCV_DIGIT1==8)
{
//Decision
//Decision: DIGIT2=4?
if (FCV_DIGIT2==4)
{
//CORRECT_CODE
//Call Macro: CORRECT_CODE
FCM_CORRECT_CODE();


} else {
//Call Macro
//Call Macro: WRONG_CODE
FCM_WRONG_CODE();


}


} else {
//Call Macro
//Call Macro: WRONG_CODE
FCM_WRONG_CODE();


}


}

void FCM_CORRECT_CODE()
{

//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" CORRECT CODE")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" PUSH THE DOOR NOW")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('P');
FCD_LCDDisplay0_PrintASCII('U');
FCD_LCDDisplay0_PrintASCII('S');
FCD_LCDDisplay0_PrintASCII('H');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('H');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('W');


//LOCK OPEN
//Output: 1 -> A0
trisa = trisa & 0xfe;
if (1)
porta = (porta & 0xfe) | 0x01;
else
porta = porta & 0xfe;


//Delay
//Delay: 3 s
delay_s(3);


//LOCK LOCKED
//Output: 0 -> A0
trisa = trisa & 0xfe;
if (0)
porta = (porta & 0xfe) | 0x01;
else
porta = porta & 0xfe;


}

void FCM_WRONG_CODE()
{

//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Loop
//Loop: Loop 5 times
for (FCLV_LOOP1=0; FCLV_LOOP1<5; FCLV_LOOP1++)
{
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" WARNING WRONG")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('W');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('I');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('G');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('W');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('G');


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII("CODE TRY AGAIN")
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('Y');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('G');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('I');
FCD_LCDDisplay0_PrintASCII('N');


//Delay
//Delay: 500 ms
delay_ms(255);
delay_ms(245);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Delay
//Delay: 500 ms
delay_ms(255);
delay_ms(245);


}


}

void main()
{

//Initialisation
adcon1 = 0x07;


//Interrupt initialisation code
option_reg = 0xC0;


//Connection Point
//Connection Point: [E]: E
FCC_Main_E:
;


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Start
FCD_LCDDisplay0_Start();


//Delay
//Delay: 250 ms
delay_ms(250);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" ENTER CODE ")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');


//Loop
//Loop: While 1
while (1)
{
//Connection Point
//Connection Point: [A]: A
FCC_Main_A:
;


//READ THE KEYPAD NOW
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//HAS THE KEYPAD BEEN PRESSED
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//WAITING FOR KEYPAD ENTRY
//Goto Connection Point: [A]: A
goto FCC_Main_A;


} else {
//ASSIGN KEYPAD NUMBER TO DIGIT1
//Calculation:
// DIGIT1 = KEYPADNUMBER
FCV_DIGIT1 = FCV_KEYPADNUMBER;


//Connection Point
//Connection Point: : B
FCC_Main_B:
;


//HAS KEYPAD BEEN RELEASED
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//HAS KEYPAD BEEN RELEASED
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//SET CUSOR LINE 2
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//DISPLAY THE FIRST DIGIT
//Call Component Macro: LCDDisplay(0)::PrintNumber(DIGIT1)
FCD_LCDDisplay0_PrintNumber(FCV_DIGIT1);


//Connection Point
//Connection Point: [C]: C
FCC_Main_C:
;


//Call Component Macro
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//Decision
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//Goto Connection Point
//Goto Connection Point: [C]: C
goto FCC_Main_C;


} else {
//Calculation
//Calculation:
// DIGIT2 = KEYPADNUMBER
FCV_DIGIT2 = FCV_KEYPADNUMBER;


}


//Connection Point
//Connection Point: [D]: D
FCC_Main_D:
;


//HAS KEYPAD BEEN RELEASED
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//TEST CODE IF CORRECT
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintNumber(DIGIT2)
FCD_LCDDisplay0_PrintNumber(FCV_DIGIT2);


//Call Macro
//Call Macro: TESTCODE
FCM_TESTCODE();


//Goto Connection Point
//Goto Connection Point: [E]: E
goto FCC_Main_E;


} else {
//Goto Connection Point
//Goto Connection Point: [D]: D
goto FCC_Main_D;


}


} else {
//Goto Connection Point
//Goto Connection Point: : B
goto FCC_Main_B;


}


}


}


mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}

//************************************************************************************
//**
//** File name: C:\Documents and Settings\Ivan Sandler\My Documents\YOU TUBE DIGITAL LOCK.c
//** Generated by: Flowcode v4.3.7.63
//** Date: Tuesday, August 31, 2010 20:03:55
//** Licence: Professional
//** Registered to: ivan sandler
//**
//**
//** http://www.matrixmultimedia.com
//************************************************************************************


#define MX_PIC

//Defines for microcontroller
#define P16F877A
#define MX_EE
#define MX_EE_TYPE2
#define MX_EE_SIZE 256
#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

//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
void FCM_TESTCODE();
void FCM_CORRECT_CODE();
void FCM_WRONG_CODE();


//Variable declarations
char FCV_KEYPADNUMBER;
char FCV_DIGIT1;
char FCV_DIGIT2;

char FCLV_LOOP1;

//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)
tris` = Row Data Direction Register
port` = Row Port Register
3 = Number Of Columns
4 = Number Of Rows
trisc = Column Data Direction Register
portc = Column Port Register
1 = Column 1 mask
2 = Column 2 mask
4 = Column 3 mask
1 = Column 4 mask
1 = Row 1 mask
1 = Row 2 mask
1 = Row 3 mask
1 = Row 4 mask
******************************/




//KeyPad(0): //Macro function declarations

char FCD_KeyPad0_GetKeypadNumber();
char FCD_KeyPad0_GetKeypadAscii();
//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_1114936 = Unique Component Reference Number
2 = Row Count
16 = Column Count
******************************/

//component connections
#define LCD_1114936_PORT0 portb
#define LCD_1114936_TRIS0 trisb
#define LCD_1114936_PORT1 portb
#define LCD_1114936_TRIS1 trisb
#define LCD_1114936_PORT2 portb
#define LCD_1114936_TRIS2 trisb
#define LCD_1114936_PORT3 portb
#define LCD_1114936_TRIS3 trisb
#define LCD_1114936_PORT4 portb
#define LCD_1114936_TRIS4 trisb
#define LCD_1114936_PORT5 portb
#define LCD_1114936_TRIS5 trisb
#define LCD_1114936_BIT0 0
#define LCD_1114936_BIT1 1
#define LCD_1114936_BIT2 2
#define LCD_1114936_BIT3 3
#define LCD_1114936_RS 4
#define LCD_1114936_E 5
#define LCD_1114936_ROWCNT 2
#define LCD_1114936_COLCNT 16

#ifdef _BOOSTC
#define LCD_1114936_DELAY delay_10us(10)
#endif
#ifdef _C2C_
#define LCD_1114936_DELAY delay_us(100)
#endif
#ifdef HI_TECH_C
#define LCD_1114936_DELAY __delay_us(120)
#endif
#ifndef LCD_1114936_DELAY
#define LCD_1114936_DELAY delay_us(100)
#endif




//LCDDisplay(0): //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);



//KeyPad(0): //Macro implementations


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,1}
#define KPAD_COL_MASK (1|2|4|1)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {1}
#define KPAD_ROW_MASK (1)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {1,1}
#define KPAD_ROW_MASK (1|1)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {1,1,1}
#define KPAD_ROW_MASK (1|1|1)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {1,1,1,1}
#define KPAD_ROW_MASK (1|1|1|1)
#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)
tris` = (tris` | KPAD_ROW_MASK);
trisc = (trisc & ~KPAD_COL_MASK); //BR

char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portc = mtxCols[iCol];

//delay
delay_us(10);

//read the port
c_ip = port`;

//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,1}
#define KPAD_COL_MASK (1|2|4|1)
#endif
#if (4 == 1)
#define KPAD_ROW_MTX {1}
#define KPAD_ROW_MASK (1)
#endif
#if (4 == 2)
#define KPAD_ROW_MTX {1,1}
#define KPAD_ROW_MASK (1|1)
#endif
#if (4 == 3)
#define KPAD_ROW_MTX {1,1,1}
#define KPAD_ROW_MASK (1|1|1)
#endif
#if (4 == 4)
#define KPAD_ROW_MTX {1,1,1,1}
#define KPAD_ROW_MASK (1|1|1|1)
#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)
tris` = (tris` | KPAD_ROW_MASK);
trisc = (trisc & ~KPAD_COL_MASK);

char iCol;
char iRow;
char c_ip;
for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column high
portc = mtxCols[iCol];

//delay
delay_us(10);

//read the port
c_ip = port`;

//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

}



//LCDDisplay(0): //Macro implementations


void FCD_LCDDisplay0_RawSend(char in, char mask)
{
unsigned char pt;

clear_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_PORT4, LCD_1114936_RS);
clear_bit(LCD_1114936_PORT5, LCD_1114936_E);
pt = ((in >> 4) & 0x0f);
if (pt & 0x01)
set_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
if (pt & 0x02)
set_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
if (pt & 0x04)
set_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
if (pt & 0x08)
set_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
if (mask)
set_bit(LCD_1114936_PORT4, LCD_1114936_RS);
LCD_1114936_DELAY;
set_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
clear_bit (LCD_1114936_PORT5, LCD_1114936_E);
pt = (in & 0x0f);
LCD_1114936_DELAY;
clear_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_PORT4, LCD_1114936_RS);
clear_bit(LCD_1114936_PORT5, LCD_1114936_E);
if (pt & 0x01)
set_bit(LCD_1114936_PORT0, LCD_1114936_BIT0);
if (pt & 0x02)
set_bit(LCD_1114936_PORT1, LCD_1114936_BIT1);
if (pt & 0x04)
set_bit(LCD_1114936_PORT2, LCD_1114936_BIT2);
if (pt & 0x08)
set_bit(LCD_1114936_PORT3, LCD_1114936_BIT3);
if (mask)
set_bit(LCD_1114936_PORT4, LCD_1114936_RS);
LCD_1114936_DELAY;
set_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
clear_bit (LCD_1114936_PORT5, LCD_1114936_E);
LCD_1114936_DELAY;
}

void FCD_LCDDisplay0_Start()
{

clear_bit(LCD_1114936_TRIS0, LCD_1114936_BIT0);
clear_bit(LCD_1114936_TRIS1, LCD_1114936_BIT1);
clear_bit(LCD_1114936_TRIS2, LCD_1114936_BIT2);
clear_bit(LCD_1114936_TRIS3, LCD_1114936_BIT3);
clear_bit(LCD_1114936_TRIS4, LCD_1114936_RS);
clear_bit(LCD_1114936_TRIS5, LCD_1114936_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_1114936_ROWCNT == 1)
y=0x80;
#endif

#if (LCD_1114936_ROWCNT == 2)
if (y==0)
y=0x80;
else
y=0xc0;
#endif

#if (LCD_1114936_ROWCNT == 4)
if (y==0)
y=0x80;
else if (y==1)
y=0xc0;

#if (LCD_1114936_COLCNT == 16)
else if (y==2)
y=0x90;
else
y=0xd0;
#endif

#if (LCD_1114936_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_1114936_ROWCNT == 1)
rowcount=80;
#endif

#if (LCD_1114936_ROWCNT == 2)
rowcount=40;
#endif

#if (LCD_1114936_ROWCNT == 4)
#if (LCD_1114936_COLCNT == 16)
rowcount=16;
#endif
#if (LCD_1114936_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);
}

//Macro implementations

void FCM_TESTCODE()
{

//FIRST NUMBER
//Decision: DIGIT1=8?
if (FCV_DIGIT1==8)
{
//Decision
//Decision: DIGIT2=4?
if (FCV_DIGIT2==4)
{
//CORRECT_CODE
//Call Macro: CORRECT_CODE
FCM_CORRECT_CODE();


} else {
//Call Macro
//Call Macro: WRONG_CODE
FCM_WRONG_CODE();


}


} else {
//Call Macro
//Call Macro: WRONG_CODE
FCM_WRONG_CODE();


}


}

void FCM_CORRECT_CODE()
{

//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" CORRECT CODE")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" PUSH THE DOOR NOW")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('P');
FCD_LCDDisplay0_PrintASCII('U');
FCD_LCDDisplay0_PrintASCII('S');
FCD_LCDDisplay0_PrintASCII('H');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('H');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('W');


//LOCK OPEN
//Output: 1 -> A0
trisa = trisa & 0xfe;
if (1)
porta = (porta & 0xfe) | 0x01;
else
porta = porta & 0xfe;


//Delay
//Delay: 3 s
delay_s(3);


//LOCK LOCKED
//Output: 0 -> A0
trisa = trisa & 0xfe;
if (0)
porta = (porta & 0xfe) | 0x01;
else
porta = porta & 0xfe;


}

void FCM_WRONG_CODE()
{

//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Loop
//Loop: Loop 5 times
for (FCLV_LOOP1=0; FCLV_LOOP1<5; FCLV_LOOP1++)
{
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" WARNING WRONG")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('W');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('I');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('G');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('W');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('G');


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII("CODE TRY AGAIN")
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII('Y');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('G');
FCD_LCDDisplay0_PrintASCII('A');
FCD_LCDDisplay0_PrintASCII('I');
FCD_LCDDisplay0_PrintASCII('N');


//Delay
//Delay: 500 ms
delay_ms(255);
delay_ms(245);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Clear
FCD_LCDDisplay0_Clear();


//Delay
//Delay: 500 ms
delay_ms(255);
delay_ms(245);


}


}

void main()
{

//Initialisation
adcon1 = 0x07;


//Interrupt initialisation code
option_reg = 0xC0;


//Connection Point
//Connection Point: [E]: E
FCC_Main_E:
;


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Start
FCD_LCDDisplay0_Start();


//Delay
//Delay: 250 ms
delay_ms(250);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::Cursor(0, 0)
FCD_LCDDisplay0_Cursor(0, 0);


//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintASCII(" ENTER CODE ")
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('N');
FCD_LCDDisplay0_PrintASCII('T');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII('R');
FCD_LCDDisplay0_PrintASCII(' ');
FCD_LCDDisplay0_PrintASCII('C');
FCD_LCDDisplay0_PrintASCII('O');
FCD_LCDDisplay0_PrintASCII('D');
FCD_LCDDisplay0_PrintASCII('E');
FCD_LCDDisplay0_PrintASCII(' ');


//Loop
//Loop: While 1
while (1)
{
//Connection Point
//Connection Point: [A]: A
FCC_Main_A:
;


//READ THE KEYPAD NOW
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//HAS THE KEYPAD BEEN PRESSED
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//WAITING FOR KEYPAD ENTRY
//Goto Connection Point: [A]: A
goto FCC_Main_A;


} else {
//ASSIGN KEYPAD NUMBER TO DIGIT1
//Calculation:
// DIGIT1 = KEYPADNUMBER
FCV_DIGIT1 = FCV_KEYPADNUMBER;


//Connection Point
//Connection Point: : B
FCC_Main_B:
;


//HAS KEYPAD BEEN RELEASED
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//HAS KEYPAD BEEN RELEASED
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//SET CUSOR LINE 2
//Call Component Macro: LCDDisplay(0)::Cursor(0, 1)
FCD_LCDDisplay0_Cursor(0, 1);


//DISPLAY THE FIRST DIGIT
//Call Component Macro: LCDDisplay(0)::PrintNumber(DIGIT1)
FCD_LCDDisplay0_PrintNumber(FCV_DIGIT1);


//Connection Point
//Connection Point: [C]: C
FCC_Main_C:
;


//Call Component Macro
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//Decision
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//Goto Connection Point
//Goto Connection Point: [C]: C
goto FCC_Main_C;


} else {
//Calculation
//Calculation:
// DIGIT2 = KEYPADNUMBER
FCV_DIGIT2 = FCV_KEYPADNUMBER;


}


//Connection Point
//Connection Point: [D]: D
FCC_Main_D:
;


//HAS KEYPAD BEEN RELEASED
//Call Component Macro: KEYPADNUMBER=KeyPad(0)::GetKeypadNumber
FCV_KEYPADNUMBER = FCD_KeyPad0_GetKeypadNumber();


//TEST CODE IF CORRECT
//Decision: KEYPADNUMBER=255?
if (FCV_KEYPADNUMBER==255)
{
//Call Component Macro
//Call Component Macro: LCDDisplay(0)::PrintNumber(DIGIT2)
FCD_LCDDisplay0_PrintNumber(FCV_DIGIT2);


//Call Macro
//Call Macro: TESTCODE
FCM_TESTCODE();


//Goto Connection Point
//Goto Connection Point: [E]: E
goto FCC_Main_E;


} else {
//Goto Connection Point
//Goto Connection Point: [D]: D
goto FCC_Main_D;


}


} else {
//Goto Connection Point
//Goto Connection Point: : B
goto FCC_Main_B;


}


}


}


mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: C ASM PROGRAMING

Post by Benj »

The problem is due to missing component connections for your keypad.

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: C ASM PROGRAMING

Post by Steve »

You must register on the Flowcode V4 forum to continue to receive support from us. Please follow the instructions in the link I sent you earlier today.

Post Reply