| |
GSM Security system. The GSM Security System supports two SIM communication, 3 alarm zones, 2 output relays, built-in battery. iButton, SMS and Voice calls control. Open hardware and free source codes.

Schematic diagram. Click to download pdf.
PCAD2006 Schematic file. Click to download.
BOM file. Bill of materials. Click to download.
Source code (IAR Embedded Workbench):
bitbyt.h
#ifndef _bit_byt_
#define _bit_byt_
#define bit(n) (1 << (n))
#define setbit(p,n) (p|=bit(n))
#define clrbit(p,n) (p&=~bit(n))
#define invbit(p,n) (p=p^bit(n))
#define tstbit(p,n) (p&bit(n))
#endif
ds1990a.h
#ifndef _ds_1990a_
#define _ds_1990a_
#define DS_PORT PORTA
#define DS_DIR DDRA
#define DS_PIN PINA
unsigned char DS_bit = 3;
#define timeA 6
#define timeB 64
#define timeC 60
#define timeD 10
#define timeE 9
#define timeF 55
#define timeG 0
#define timeH 480
#define timeI 70
#define timeJ 410
#define DS1990A_ID 0x01 // READ ROM command code
#define W1_ROM_READ 0x33 // READ ROM command code
unsigned char uidDS[8];
unsigned char w1_read(void);
void w1_write(unsigned char data);
unsigned char w1_init(void);
unsigned char w1_readBit(void);
void w1_writeBit(unsigned char bit);
unsigned char ds1990a_init(void);
unsigned char testDQ(void);
unsigned char CRC8(unsigned char *ptr, unsigned char count);
unsigned char testDQ(void)
{
if (tstbit(DS_PIN,DS_bit)) return 1;
else return 0;
}
void setDQ()
{
clrbit(DS_DIR,DS_bit);
__no_operation();
}
void clrDQ()
{
setbit(DS_DIR,DS_bit);
clrbit(DS_PORT,DS_bit);
}
unsigned char w1_read(void)
{
int loop, result=0;
__disable_interrupt();
for (loop = 0; loop < 8; loop++)
{
result >>= 1;
if (w1_readBit())
result |= 0x80;
}
__enable_interrupt();
return result;
}
void w1_write(unsigned char data)
{
int loop;
__disable_interrupt();
for (loop = 0; loop < 8; loop++)
{
w1_writeBit(data & 0x01);
data >>= 1;
}
__enable_interrupt();
}
unsigned char w1_init(void)
{
int result;
__disable_interrupt();
delay_us(timeG);
clrDQ();
delay_us(timeH);
setDQ();
delay_us(timeI);
result = testDQ();
delay_us(timeJ);
__enable_interrupt();
return result;
}
unsigned char w1_readBit(void)
{
int result;
clrDQ();
delay_us(timeA);
setDQ();
delay_us(timeE);
result = testDQ();
delay_us(timeF);
return result;
}
void w1_writeBit(unsigned char bit)
{
if (bit)
{
clrDQ();
delay_us(timeA);
setDQ();
delay_us(timeB);
}
else
{
clrDQ();
delay_us(timeC);
setDQ();
delay_us(timeD);
}
}
unsigned char ds1990a_init(void)
{
unsigned char i;
if (w1_init())
{
for (i=0; i<8; i++)
uidDS[i] = 0;
return 0;
}
else
{
w1_write(W1_ROM_READ);
for (i=0; i<8; i++)
uidDS[i] = w1_read();
return 1;
}
}
unsigned char CRC8(unsigned char *ptr, unsigned char count)
{
unsigned char crc=0;
unsigned char i, c, tmp;
while (count-- != 0)
{
c = *ptr++;
i = 8;
do
{
tmp=c;
tmp ^= crc;
crc >>= 1;
c >>= 1;
if(tmp & 1)
{
crc ^= 0x8C;
}
}
while(--i);
}
return crc;
}
#endif
eeprom.h
#ifndef _eeprom_defs_
#define _eeprom_defs_
__eeprom __no_init unsigned char Loop1Set @ 0x01;
__eeprom __no_init unsigned char Loop2Set @ 0x02;
__eeprom __no_init unsigned char Loop3Set @ 0x03;
#define MAX_IB_KEYS 20
#define IB_KEY_LENGTH 8
__eeprom __no_init unsigned char CurrentKeys @ 004;
__eeprom __no_init unsigned char ibKeys[MAX_IB_KEYS][IB_KEY_LENGTH] @ 0x05;
#endif
madelay.h
#ifndef _ma_delay_
#define _ma_delay_
#define delay_us(c) __delay_cycles(MasterClock/1000000*c)
#define delay_ms(c) __delay_cycles(MasterClock/1000*c)
#endif
main.h
#ifndef _main_
#define _main_
#include <iom128.h>
#include <inavr.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "bitbyt.h"
#include "portdefines.h"
#include "madelay.h" // Delays
#include "eeprom.h" // EEPROM
#include "ds1990a.h" // iButton
#define ADC_VREF_TYPE 0x00
#define TXDELAY 10000
#define CtrlZ 0x1A // Ctrl-Z
#define T1_OVF 0x01
#define DF_BIT_READY 7
#define MAX_BUFFER 264
#define MAX_PAGE 2048
unsigned int temp = 0;
unsigned int temp1 = 0;
unsigned char iButtonLock = 0;
unsigned char RepeatedKey = 0;#define DATA_REGISTER_EMPTY_0 (1<<UDRE0)
#define FRAMING_ERROR_1 (1<<FE1)
#define PARITY_ERROR_1 (1<<UPE1)
#define DATA_OVERRUN_1 (1<<DOR1)
#define DATA_REGISTER_EMPTY_1 (1<<UDRE1)
#define RXBUFLENGTH_1 256
volatile char RxBuffer[RXBUFLENGTH_1];
volatile char RxBufWritePoint = 0;
char RxBufReadPoint = 0;
char ReceiveString[RXBUFLENGTH_1] = "";
char AbRecReadComplete = 0;
#define MAX_AB_NUMBER 5
#define MAX_NUMBER_LENGTH 15
#define MAX_RECORD_LENGTH 17
#define MAX_NAME_LENGTH 8
#define MAX_PASS_LENGTH 3
#define SERVICE_NUM_LENGTH 5
char AbNumber [MAX_AB_NUMBER][MAX_NUMBER_LENGTH+1];
char AbRecord [MAX_AB_NUMBER][MAX_RECORD_LENGTH+1];
char AbName [MAX_AB_NUMBER][MAX_NAME_LENGTH+1];
char AbPass [MAX_AB_NUMBER][MAX_PASS_LENGTH+1];
char GuestPass [MAX_PASS_LENGTH+1];
char AbProfile [MAX_AB_NUMBER];
char AbCallTime [MAX_AB_NUMBER];
char AbCallNum [MAX_AB_NUMBER];
char AbExtService[MAX_AB_NUMBER];
char AbActive [MAX_AB_NUMBER];
unsigned char IncorrectAb = 0;
char Sending220VOFF = 0;
char Sending220VON = 1;
char SendingPOWOFF = 0;
char DelayGuardOnTime = 3;
char DelayGuardOffTime = 30;
char iButtonUse = 0;
char LockOpenTime = 9;
char SirenSingTime = 90;
char GuardSource = 0;
char PreparationGuardTime = 0;
#define REPEAT_GUARD_TIME 180
#define GS_SWITCHER 1
#define GS_IBUTTON 4
#define GS_SMS 2
#define GS_DTMF 3
char PowerCorrect = 1;
char GSMStatus = 0;
char GSMSigStrength = 0;
char SIMNum = 0;
char SIMFault = 0;
char Loop1On = 0;
char Loop2On = 0;
char Loop3On = 0;
#define HI_J_LIMIT 750
#define LO_J_LIMIT 250
char Loop1Status = 0;
char Loop2Status = 0;
char Loop3Status = 0;
#define HI_LOOP_LIMIT 527
#define LO_LOOP_LIMIT 304
char Loop1Violation = 0;
char Loop2Violation = 0;
char Loop3Violation = 0;
char NewLoopViolation = 0;
char OldLoopViolation = 0;
char OldLoop1Violation = 0;
char OldLoop2Violation = 0;
char OldLoop3Violation = 0;
char LoopViolation = 0;
char GuardSourceL1 = 1;
char GuardSourceL2 = 1;
char GuardSourceL3 = 1;
char TotalHackLoops = 0;
char HackLoopsCount = 0;
#define NLOOPS 3
char IndicatedLoops[NLOOPS] = {0, 0, 0};
char AccStatus = 0;
#define ACC_CORRECT 499
#define ACC_FAULT 439
char Relay1On = 0;
char Relay2On = 0;
char Out1On = 0;
char Out2On = 0;
#define SMS_TIMEOUT 30
char EconoMode = 0;
char SMSorDTMFEconoMode = 0;
char iButtonMode = 0;
unsigned int CurrentADCRead = 0;
typedef enum {UART_0, UART_1} t_uarts;
static t_uarts g_currentUsart = UART_1;
void BeginInit();
unsigned int ReadADC(unsigned char ADCInput);
void SetActiveUart (t_uarts u)
{
g_currentUsart = u;
}
int putchar( int data );
void ClearRxBuffer(void);
void SystemUpdate(void);
void GR_On(void);
void GR_Off(void);
void StringBuilder(void);
char ReadAbRecords(void);
char LoopTest(void);
int StrToInt (char* InputStr);
void iButtonNewKeysSearch(void);
void iButtonKeysErase(void);
unsigned char iButtonKeyScan(void);
void DF_WriteSPI(unsigned char data);
unsigned char DF_Status( void );
unsigned char DF_Ready( void );
void DF_NextPageToNextBuffer (unsigned char active_buffer, unsigned int page_counter);
void DF_Playback (void);
void DF_ActiveBufferToSpeaker (unsigned char active_buffer);
void DF_MainMemoryToSpeaker(unsigned int Page);
void DF_PagesToSpeaker(unsigned int StartPage, unsigned int EndPage);
void GuardIn (unsigned char InGuardSource);
void GuardOut (unsigned char OutGuardSource);
void LoopsRead (void);
void GuardReaxion(void);
void BeginInit(void)
{
DDRA = (1<<POUT2);
PORTA = (1<<JIBP) | (1<<JIBM);
DDRB = ((1<<SCK) | (1<<SI) | (1<<PWDN) | (1<<CHARG) | (1<<SPKOUT) | (POUT1));
PORTB = 0;
DDRC = ((1<<SIMSW) | (1<<EGRDLED) | (1<<EGSMLED) | (1<<EPOWLED) | (1<<GRDLED) | (1<<GSMLED) | (1<<POWLED));
PORTC = 0;
DDRD = ((1<<PON) | (1<<PDTR) | (1<<PTD) | (1<<PRTS));
PORTD = 0;
DDRE = (1<<CON) | (1<<TXD0);
PORTE = (1<<CON);
DDRF = 0;
PORTF = 0;
DDRG = ((1<<nFCS) | (1<<nFRES) | (1<<nGSMPOW) | (1<<K1) | (1<<K2));
PORTG = (1<<nFRES);
ADMUX = ADC_VREF_TYPE;
ADCSRA = 0x87;
SFIOR &= 0xEF;
UCSR0A = 0x00;
UCSR0B = 0x08;
UCSR0C = 0x06;
UBRR0H = 0x00;
UBRR0L = 0x33;
UCSR1A = 0x00;
UCSR1B = 0x98;
UCSR1C = 0x06;
UBRR1H = 0x00;
UBRR1L = 0x33;
TCCR0 = 7;
TIMSK = 1<<TOIE0;
EICRA = 0x00;
EICRB = 0x03;
EIMSK = 0x10;
EIFR = 0x10;
if (Loop1Set == 0xFF)
Loop1Set = 1;
if (Loop2Set == 0xFF)
Loop2Set = 1;
if (Loop3Set == 0xFF)
Loop3Set = 1;
if (CurrentKeys == 0xFF)
CurrentKeys = 0;
}
unsigned int ReadADC(unsigned char ADCInput)
{
ADMUX = ADCInput | ADC_VREF_TYPE;
ADCSRA |= 0x40;
while ((ADCSRA & 0x10) == 0);
ADCSRA|=0x10;
return (unsigned int)(ADCL | (ADCH<<8));
}
int putchar( int data )
{
if (g_currentUsart == UART_1)
{
while ( !( UCSR1A & DATA_REGISTER_EMPTY_1) );
UDR1 = data;
} else
{
while ( !( UCSR0A & DATA_REGISTER_EMPTY_0) );
UDR0 = data;
}
__delay_cycles(TXDELAY);
return data;
}
void ClearRxBuffer(void)
{
unsigned int ClearPoint = 0;
for (; ClearPoint++ < RXBUFLENGTH_1; RxBuffer[ClearPoint] = 0);
RxBufReadPoint = 0;
RxBufWritePoint = 0;
}
char LoopTest(void)
{
if (Loop1On == 1)
if ((Loop1Status == 0) || (Loop1Status == 2))
GuardSourceL1 = 1;
else GuardSourceL1 = 0;
if (Loop1On == 2)
if ((Loop1Status == 0) || (Loop1Status == 1))
GuardSourceL1 = 1;
else GuardSourceL1 = 0;
if (Loop2On == 1)
if ((Loop2Status == 0) || (Loop2Status == 2))
GuardSourceL2 = 1;
else GuardSourceL2 = 0;
if (Loop2On == 2)
if ((Loop2Status == 0) || (Loop2Status == 1))
GuardSourceL2 = 1;
else GuardSourceL2 = 0;
if (Loop3On == 1)
if ((Loop3Status == 0) || (Loop3Status == 2))
GuardSourceL3 = 1;
else GuardSourceL3 = 0;
if (Loop3On == 2)
if ((Loop3Status == 0) || (Loop3Status == 1))
GuardSourceL3 = 1;
else GuardSourceL3 = 0;
if ((GuardSourceL1 == 1) && (GuardSourceL2 == 1) && (GuardSourceL3 == 1) &&
((Loop1On != 0) || (Loop2On != 0) || (Loop3On != 0))) return 1;
else return 0;
}
#define DTMF_PASS_LENGTH 4
#define DTMF_COMMAND_LENGTH 2
volatile char DTMFPassBuf[DTMF_PASS_LENGTH+1] = "";
volatile unsigned char DTMFPassPos = 0;
#define DTMF_PASS_TIMEOUT 10
#define DTMF_COMMAMD_TIMEOUT 30
unsigned char DTMFIncomingUser = 0;
#define DTMF_SHARP 12
#pragma vector = INT4_vect
__interrupt void INT4_vect_Interrupt(void)
{
if (DTMFPassPos < DTMF_PASS_LENGTH)
{
DTMFPassBuf[DTMFPassPos] = ((PINE >> DTQ1) & 0x01) | ((PINE >> (DTQ2 - 1)) & 0x02) | ((PINE >> (DTQ3 - 2)) & 0x04) | ((PINE >> (DTQ4 - 3)) & 0x08);
if (DTMFPassBuf[DTMFPassPos] == 10) DTMFPassBuf[DTMFPassPos] = 0;
DTMFPassPos++;
}
}
#pragma vector = USART1_RXC_vect
__interrupt void USART1_RXC_Interrupt(void)
{
RxBuffer[RxBufWritePoint] = UDR1;
if (RxBufWritePoint == RXBUFLENGTH_1-1)
RxBufWritePoint = 0;
else RxBufWritePoint++;
}
volatile unsigned long Ticks = 0;
volatile unsigned char TmSS = 0;
volatile unsigned char TmIndLoop = 0;
unsigned char AttemptInError = 0;
volatile unsigned char TmErrRec = 0;
volatile unsigned char TmSirenSingTime = 0;
volatile unsigned char TmLockOpenTime = 0;
volatile unsigned char TmGuardOffTimeout = 0;
#pragma vector = TIMER0_OVF_vect
__interrupt void TIMER0_OVF_Interrupt (void)
{
#define TmQuartSeconds 7
#define TmHalfSeconds 15
#define TmFullSeconds 30
#define TmTwoFullSeconds 56 .}
#define TmFullSSPeriod 160
++Ticks;
if (Ticks % TmHalfSeconds == 0)
if (PowerCorrect == 0) invbit(PORTC, POWLED);
else setbit(PORTC, POWLED);
if (Ticks % TmFullSSPeriod == 0)
{
TmSS = 2*GSMSigStrength;
clrbit(PORTC, GSMLED);
TmErrRec = 2*IncorrectAb;
clrbit(PORTC, GRDLED);
if (TotalHackLoops != 0)
{
TmIndLoop = 2*IndicatedLoops[HackLoopsCount];
if (HackLoopsCount == (TotalHackLoops - 1))
HackLoopsCount = 0;
else
HackLoopsCount++;
}
}
if (Ticks % TmQuartSeconds == 0)
{
if ((TotalHackLoops != 0) && (GuardSource == 0) && (TmIndLoop > 0))
{
invbit(PORTC, GRDLED);
TmIndLoop--;
}
else
if ((AttemptInError == 1) && (Ticks % TmFullSeconds == 0))
invbit(PORTC, GRDLED);
else
if ((GuardSource != 0) && (Ticks % TmTwoFullSeconds == 0))
setbit(PORTC, GRDLED);
else
if (TmErrRec > 0)
{
invbit(PORTC, GRDLED);
TmErrRec--;
}
else clrbit(PORTC, GRDLED);
if (GSMStatus == 0) clrbit(PORTC, GSMLED);
if (GSMStatus == 1) invbit(PORTC, GSMLED);
if (GSMStatus == 2)
{
if (TmSS > 0)
{
invbit(PORTC, GSMLED);
TmSS--;
}
else clrbit(PORTC, GSMLED);
}
if (GSMStatus == 3)
setbit(PORTC, GSMLED);
}
if ((GuardSource != 0) && (Ticks % TmFullSeconds == 0))
if (PreparationGuardTime != 0)
PreparationGuardTime--;
if (Ticks % TmFullSeconds == 0)
{
if (TmSirenSingTime > 0)
{
setbit(PORTB, POUT1);
TmSirenSingTime--;
}
else
clrbit(PORTB, POUT1);
if (TmLockOpenTime > 0)
{
setbit(PORTA, POUT2);
TmLockOpenTime--;
}
else
clrbit(PORTA, POUT2);
if (TmGuardOffTimeout > 0)
TmGuardOffTimeout--;
if ((GuardSource != 0) && (PreparationGuardTime == 0))
{
LoopsRead ();
if (LoopTest() == 1)
{
SetActiveUart(UART_0);
printf("*\n\r");
SetActiveUart(UART_1);
}
else {
OldLoopViolation = NewLoopViolation;
OldLoop1Violation = Loop1Violation;
OldLoop2Violation = Loop2Violation;
OldLoop3Violation = Loop3Violation;
if (GuardSourceL1 == 0) Loop1Violation = 1;
if (GuardSourceL2 == 0) Loop2Violation = 1;
if (GuardSourceL3 == 0) Loop3Violation = 1;
NewLoopViolation = Loop1Violation + Loop2Violation + Loop3Violation;
if (NewLoopViolation > OldLoopViolation)
{
LoopViolation = 1;
TmGuardOffTimeout = DelayGuardOffTime;
}
if (OldLoop1Violation != Loop1Violation)
{
IndicatedLoops[TotalHackLoops] = 1;
TotalHackLoops++;
}
if (OldLoop2Violation != Loop2Violation)
{
IndicatedLoops[TotalHackLoops] = 2;
TotalHackLoops++;
}
if (OldLoop3Violation != Loop3Violation)
{
IndicatedLoops[TotalHackLoops] = 3;
TotalHackLoops++;
}
SetActiveUart(UART_0);
printf("Viol = %d %d %d = %d\n\r", Loop1Violation, Loop2Violation, Loop3Violation, LoopViolation);
SetActiveUart(UART_1);
}
}
}
}
signed char ReadData(void)
{
char data;
if (RxBufWritePoint == RxBufReadPoint) return -1;
data = RxBuffer[RxBufReadPoint];
if(RxBufReadPoint == RXBUFLENGTH_1-1) RxBufReadPoint = 0;
else RxBufReadPoint++;
return data;
}
void SystemUpdate(void)
{
unsigned char MessageDecoding = 0;
#define MAX_LENGTH (sizeof("#Y#ZZZ"))
char PassPlusCode[MAX_LENGTH];
#define MAX_LENGTH_NEW_REC (sizeof("#12#1 +79161234567 User1*123А151*"))
char NewRecIncom[MAX_LENGTH_NEW_REC];
char StarCount = 0;
char BlankCount = 0;
char AbNewPos = 0;
char Ab11Number [MAX_NUMBER_LENGTH+1];
char Ab11Record [MAX_RECORD_LENGTH+1];
char AbNumCount = 0;
char AbRecCount = 0;
char MessageLength = 0;
PassPlusCode[0] = 0;
NewRecIncom[0] = 0;
if (((PINC & (1<<EXTKEY)) != 0) && (GuardSource == 0))
GuardIn(GS_SWITCHER);
if (((PINC & (1<<EXTKEY)) == 0) && (GuardSource != 0))
GuardOut(GS_SWITCHER);
iButtonLock = 0;
for (temp = 0; temp <= 300; temp++)
{
delay_ms(1);
temp1 = iButtonKeyScan();
if ((temp1 == 1) && (GuardSource == 0))
{
iButtonLock = 1;
GuardIn(GS_IBUTTON);
break;
}
if ((temp1 == 1) && (GuardSource != 0))
{
iButtonLock = 1;
GuardOut(GS_IBUTTON);
break;
}
}
#define SOUND_FACTOR 8000
#define VVEDITE_START 5.9
#define VVEDITE_START_DF VVEDITE_START*(SOUND_FACTOR/MAX_BUFFER)
#define VVEDITE_END 7
#define VVEDITE_END_DF VVEDITE_END*(SOUND_FACTOR/MAX_BUFFER)
#define PAROL_START 7
#define PAROL_START_DF PAROL_START*(SOUND_FACTOR/MAX_BUFFER)
#define PAROL_END 7.5
#define PAROL_END_DF PAROL_END*(SOUND_FACTOR/MAX_BUFFER)
#define KOMANDU_START 7.5
#define KOMANDU_START_DF KOMANDU_START*(SOUND_FACTOR/MAX_BUFFER)
#define KOMANDU_END 8.3
#define KOMANDU_END_DF KOMANDU_END*(SOUND_FACTOR/MAX_BUFFER)
#define SLKOMANDU_START 8.3
#define SLKOMANDU_START_DF SLKOMANDU_START*(SOUND_FACTOR/MAX_BUFFER)
#define SLKOMANDU_END 9.8
#define SLKOMANDU_END_DF SLKOMANDU_END*(SOUND_FACTOR/MAX_BUFFER)
#define RELE_START 12.9
#define RELE_START_DF RELE_START*(SOUND_FACTOR/MAX_BUFFER)
#define RELE_END 13.7
#define RELE_END_DF RELE_END*(SOUND_FACTOR/MAX_BUFFER)
#define ODIN_START 4
#define ODIN_START_DF ODIN_START*(SOUND_FACTOR/MAX_BUFFER)
#define ODIN_END 4.5
#define ODIN_END_DF ODIN_END*(SOUND_FACTOR/MAX_BUFFER)
#define DVA_START 4.7
#define DVA_START_DF DVA_START*(SOUND_FACTOR/MAX_BUFFER)
#define DVA_END 5.5
#define DVA_END_DF DVA_END*(SOUND_FACTOR/MAX_BUFFER)
#define TRI_START 5.4
#define TRI_START_DF TRI_START*(SOUND_FACTOR/MAX_BUFFER)
#define TRI_END 5.9
#define TRI_END_DF TRI_END*(SOUND_FACTOR/MAX_BUFFER)
#define VKL_START 13.9
#define VKL_START_DF VKL_START*(SOUND_FACTOR/MAX_BUFFER)
#define VKL_END 14.6
#define VKL_END_DF VKL_END*(SOUND_FACTOR/MAX_BUFFER)
#define VIKL_START 14.6
#define VIKL_START_DF VIKL_START*(SOUND_FACTOR/MAX_BUFFER)
#define VIKL_END 15.5
#define VIKL_END_DF VIKL_END*(SOUND_FACTOR/MAX_BUFFER)
#define VKLA_START 11.1
#define VKLA_START_DF VKLA_START*(SOUND_FACTOR/MAX_BUFFER)
#define VKLA_END 12
#define VKLA_END_DF VKLA_END*(SOUND_FACTOR/MAX_BUFFER)
#define VIKLA_START 11.9
#define VIKLA_START_DF VIKLA_START*(SOUND_FACTOR/MAX_BUFFER)
#define VIKLA_END 13.0
#define VIKLA_END_DF VIKLA_END*(SOUND_FACTOR/MAX_BUFFER)
#define VKLN_START 16.8
#define VKLN_START_DF VKLN_START*(SOUND_FACTOR/MAX_BUFFER)
#define VKLN_END 17.6
#define VKLN_END_DF VKLN_END*(SOUND_FACTOR/MAX_BUFFER)
#define VIKLN_START 17.6
#define VIKLN_START_DF VIKLN_START*(SOUND_FACTOR/MAX_BUFFER)
#define VIKLN_END 18.5
#define VIKLN_END_DF VIKLN_END*(SOUND_FACTOR/MAX_BUFFER)
#define SIGNAL_START 9.7
#define SIGNAL_START_DF SIGNAL_START*(SOUND_FACTOR/MAX_BUFFER)
#define SIGNAL_END 11.1
#define SIGNAL_END_DF SIGNAL_END*(SOUND_FACTOR/MAX_BUFFER)
#define EMODE_START 15.5
#define EMODE_START_DF EMODE_START*(SOUND_FACTOR/MAX_BUFFER)
#define EMODE_END 16.9
#define EMODE_END_DF EMODE_END*(SOUND_FACTOR/MAX_BUFFER)
#define ERROR_START 18.5
#define ERROR_START_DF ERROR_START*(SOUND_FACTOR/MAX_BUFFER)
#define ERROR_END 20.5
#define ERROR_END_DF ERROR_END*(SOUND_FACTOR/MAX_BUFFER)
if (AbRecReadComplete)
{
printf("AT+CPMS=\"SM\",\"SM\",\"SM\"\n\r");
delay_ms(500);
printf("AT+CMGL=\"REC UNREAD\"\n\r");
for (temp = 0; temp <= 1500; temp++)
{
delay_ms(1);
temp1 = iButtonKeyScan();
if ((temp1 == 1) && (GuardSource == 0) && (iButtonLock == 0))
{
GuardIn(GS_IBUTTON);
break;
}
if ((temp1 == 1) && (GuardSource != 0) && (iButtonLock == 0))
{
GuardOut(GS_IBUTTON);
break;
}
}
StringBuilder();
temp1 = 0;
while ((strstr(ReceiveString, "OK") == NULL) && (strstr(ReceiveString, "ERROR") == NULL) && (temp1 < 10))
{
temp1++;
StringBuilder();
delay_ms(1000);
}
SetActiveUart(UART_0);
printf("Call Check\n\r");
SetActiveUart(UART_1);
if (strstr(ReceiveString, "RING") != NULL)
{
SetActiveUart(UART_0);
printf("Incoming Call\n\r");
SetActiveUart(UART_1);
for (temp = 0; temp < MAX_AB_NUMBER; temp++)
if ((AbProfile[temp] != 'D')
&& (strstr(ReceiveString, AbName[temp]) != NULL))
{
DTMFIncomingUser = temp;
SetActiveUart(UART_0);
printf("Incoming User = %s \n\r", AbName[temp]);
SetActiveUart(UART_1);
}
DTMFPassPos = 0;
DTMFPassBuf[0] = 0;
DTMFPassBuf[1] = 0;
DTMFPassBuf[2] = 0;
DTMFPassBuf[3] = 0;
printf("ATA\n\r");
clrbit(TIMSK, TOIE0);
setbit(PORTC, GSMLED);
clrbit(PORTB, PWDN);
StringBuilder();
DF_PagesToSpeaker(VVEDITE_START_DF, VVEDITE_END_DF);
DF_PagesToSpeaker(PAROL_START_DF, PAROL_END_DF);
temp = 0;
while((temp < DTMF_PASS_TIMEOUT) && (DTMFPassPos < DTMF_PASS_LENGTH))
{
delay_ms(1000);
StringBuilder();
temp++;
}
if (((DTMFPassBuf[0] == AbPass[DTMFIncomingUser][0] - 48) &&
(DTMFPassBuf[1] == AbPass[DTMFIncomingUser][1] - 48) &&
(DTMFPassBuf[2] == AbPass[DTMFIncomingUser][2] - 48)) ||
((DTMFPassBuf[0] == GuestPass[0] - 48) &&
(DTMFPassBuf[1] == GuestPass[1] - 48) &&
(DTMFPassBuf[2] == GuestPass[2] - 48)))
{
DTMFPassPos = 0;
temp = 0;
DF_PagesToSpeaker(VVEDITE_START_DF, VVEDITE_END_DF);
DF_PagesToSpeaker(KOMANDU_START_DF, KOMANDU_END_DF);
while(temp < DTMF_COMMAMD_TIMEOUT)
{
delay_ms(1000);
StringBuilder();
temp++;
if (DTMFPassPos == DTMF_COMMAND_LENGTH)
{
DTMFPassPos = 0;
temp = 0;
if (((DTMFPassBuf[0] < 7) || (DTMFPassBuf[0] == 9)) && (DTMFPassBuf[1] == DTMF_SHARP))
{
switch (DTMFPassBuf[0])
{
case 0:
GuardOut(GS_DTMF);
DF_PagesToSpeaker(SIGNAL_START_DF, SIGNAL_END_DF);
DF_PagesToSpeaker(VIKLA_START_DF, VIKLA_END_DF);
break;
case 1:
GuardIn(GS_DTMF);
DF_PagesToSpeaker(SIGNAL_START_DF, SIGNAL_END_DF);
DF_PagesToSpeaker(VKLA_START_DF, VKLA_END_DF);
break;
case 2:
setbit(PORTG, K1);
DF_PagesToSpeaker(RELE_START_DF, RELE_END_DF);
DF_PagesToSpeaker(ODIN_START_DF, ODIN_END_DF);
DF_PagesToSpeaker(VKL_START_DF, VKL_END_DF);
break;
case 3:
clrbit(PORTG, K1);
DF_PagesToSpeaker(RELE_START_DF, RELE_END_DF);
DF_PagesToSpeaker(ODIN_START_DF, ODIN_END_DF);
DF_PagesToSpeaker(VIKL_START_DF, VIKL_END_DF);
break;
case 4:
setbit(PORTG, K2);
DF_PagesToSpeaker(RELE_START_DF, RELE_END_DF);
DF_PagesToSpeaker(DVA_START_DF, DVA_END_DF);
DF_PagesToSpeaker(VKL_START_DF, VKL_END_DF);
break;
case 5:
clrbit(PORTG, K2);
DF_PagesToSpeaker(RELE_START_DF, RELE_END_DF);
DF_PagesToSpeaker(DVA_START_DF, DVA_END_DF);
DF_PagesToSpeaker(VIKL_START_DF, VIKL_END_DF);
break;
case 6:
DF_PagesToSpeaker(SIGNAL_START_DF, SIGNAL_END_DF);
if (GuardSource == 0)
DF_PagesToSpeaker(VIKLA_START_DF, VIKLA_END_DF);
else
DF_PagesToSpeaker(VKLA_START_DF, VKLA_END_DF);
break;
case 9:
DF_PagesToSpeaker(EMODE_START_DF, EMODE_END_DF);
if (PowerCorrect == 0)
{
SMSorDTMFEconoMode = 1;
DF_PagesToSpeaker(VKLN_START_DF, VKLN_END_DF);
}
else
DF_PagesToSpeaker(VIKLN_START_DF, VIKLN_END_DF);
break;
}
DF_PagesToSpeaker(VVEDITE_START_DF, VVEDITE_END_DF);
DF_PagesToSpeaker(SLKOMANDU_START_DF, SLKOMANDU_END_DF);
}
else
{
DF_PagesToSpeaker(ERROR_START_DF, ERROR_END_DF);
}
}
}
}
printf("ATH\n\r");
clrbit(PORTC, GSMLED);
setbit(TIMSK, TOIE0);
delay_ms(2000);
StringBuilder();
}
MessageLength = strlen(ReceiveString);
if ((strstr(ReceiveString, "#0#") != NULL)
||(strstr(ReceiveString, "#1#") != NULL)
||(strstr(ReceiveString, "#2#") != NULL)
||(strstr(ReceiveString, "#3#") != NULL)
||(strstr(ReceiveString, "#4#") != NULL)
||(strstr(ReceiveString, "#5#") != NULL)
||(strstr(ReceiveString, "#6#") != NULL)
||(strstr(ReceiveString, "#7#") != NULL)
||(strstr(ReceiveString, "#9#") != NULL)
||(strstr(ReceiveString, "#10#") != NULL)
||(strstr(ReceiveString, "#11#") != NULL))
{
for (temp = 0; temp < MAX_AB_NUMBER; temp++)
{
if ((AbProfile[temp] != 'D')
&& (strncmp(AbName[temp], "##", sizeof("##")) != 0)
&& (strstr(ReceiveString, AbPass[temp]) != NULL)
&& (strstr(ReceiveString, AbName[temp]) != NULL))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[temp]);
delay_ms(2000);
if ((strstr(ReceiveString, "#0#") != NULL) && (GuardSource != 0))
{
GuardOut(GS_SMS);
printf(" GUARD OFF");
MessageDecoding = 1;
}
if ((strstr(ReceiveString, "#1#") != NULL) && (GuardSource == 0) && (LoopTest() == 1))
{
GuardIn(GS_SMS);
printf(" GUARD ON");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#2#") != NULL)
{
setbit(PORTG, K1);
printf(" Rele 1 ON");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#3#") != NULL)
{
clrbit(PORTG, K1);
printf(" Rele 1 OFF");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#4#") != NULL)
{
setbit(PORTG, K2);
printf(" Rele 2 ON");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#5#") != NULL)
{
clrbit(PORTG, K2);
printf(" Rele 2 OFF");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#6#") != NULL)
{
if (GuardSource == 0)
printf(" GUARD OFF");
else
printf(" GUARD ON");
MessageDecoding = 1;
}
if (strstr(ReceiveString, "#9#") != NULL)
{
MessageDecoding = 1;
if (PowerCorrect == 0)
{
SMSorDTMFEconoMode = 1;
printf(" Forced EconoMode ON");
}
else
printf(" Forced EconoMode NOT TO HOLD");
}
if ((strstr(ReceiveString, "#10#") != NULL) && (strstr(ReceiveString, "ADMIN") != NULL))
{
MessageDecoding = 1;
strncpy(PassPlusCode, strstr(ReceiveString, "#10#"), sizeof("#10#X")-1);
temp1 = PassPlusCode[4] - 48;
printf("%d %s %s", temp1, AbNumber[temp1-1], AbRecord[temp1-1]);
}
if ((strstr(ReceiveString, "#11#") != NULL) && (strstr(ReceiveString, "ADMIN") != NULL))
{
strncpy(NewRecIncom, strstr(ReceiveString, "#11#"), sizeof(NewRecIncom));
SetActiveUart(UART_0);
printf("NewRecIncom = %s\n\r", NewRecIncom);
SetActiveUart(UART_1);
AbNewPos = NewRecIncom[4] - 48;
for (temp1 = 0; temp1 <= strlen(NewRecIncom); temp1++)
{
if ((BlankCount == 1) && (isdigit(NewRecIncom[temp1])))
{
Ab11Number[AbNumCount] = NewRecIncom[temp1];
Ab11Number[AbNumCount + 1] = 0;
AbNumCount++;
}
if ((BlankCount == 2) && (StarCount < 2))
{
Ab11Record[AbRecCount] = NewRecIncom[temp1];
Ab11Record[AbRecCount + 1] = 0;
AbRecCount++;
}
if (NewRecIncom[temp1] == ' ')
BlankCount++;
if (NewRecIncom[temp1] == '*')
StarCount++;
}
SetActiveUart(UART_0);
printf("AbNewPos = %d\n\r", AbNewPos);
printf("Ab11Number = %s\n\r", Ab11Number);
printf("Ab11Record = %s\n\r", Ab11Record);
SetActiveUart(UART_1);
MessageDecoding = 11;
printf(" User redefined as: %d %s %s ", AbNewPos, Ab11Number, Ab11Record);
}
if (strstr(ReceiveString, "#7#") != NULL)
{
MessageDecoding = 1;
strncpy(PassPlusCode, strstr(ReceiveString, "#7#"), sizeof(PassPlusCode)-1);
if ((PassPlusCode[3] - 48 <= 2) && (PassPlusCode[4] - 48 <= 2) && (PassPlusCode[5] - 48 <= 2))
{
switch (PassPlusCode[3] - 48)
{
case 0 :
Loop1Set = 0;
break;
case 1 :
Loop1Set = 2;
break;
case 2 :
Loop1Set = 1;
break;
}
switch (PassPlusCode[4] - 48)
{
case 0 :
Loop2Set = 0;
break;
case 1 :
Loop2Set = 2;
break;
case 2 :
Loop2Set = 1;
break;
}
switch (PassPlusCode[5] - 48)
{
case 0 :
Loop3Set = 0;
break;
case 1 :
Loop3Set = 2;
break;
case 2 :
Loop3Set = 1;
break;
}
printf(" Loops status redefined");
}
else
printf(" ERROR - loops status NOT redefined");
}
if (MessageDecoding == 0)
printf(" ERROR MESSAGE");
printf("%c",CtrlZ);
delay_ms(4000);
StringBuilder();
if (MessageDecoding == 11)
{
printf("AT+CPBW=%d,\"%s\",129,\"%s\"\n\r", AbNewPos, Ab11Number, Ab11Record);
delay_ms(2000);
StringBuilder();
AbRecReadComplete = 0;
}
}
}
}
if (MessageLength > 70)
{
printf("AT+CMGD = 1\n\r");
delay_ms(500);
StringBuilder();
}
}
Loop1On = Loop1Set;
Loop2On = Loop2Set;
Loop3On = Loop3Set;
temp = ReadADC(VBAT);
if (((temp <= ACC_FAULT) || (SMSorDTMFEconoMode == 1)) && (PowerCorrect == 0))
{
EconoMode = 1;
if (AbRecReadComplete)
{
if ((SendingPOWOFF == 0) && (SMSorDTMFEconoMode == 0))
{
for (temp = 0; temp < MAX_AB_NUMBER; temp++)
{
if ((strncmp(AbName[temp], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[temp], "##", sizeof("##")) != 0)
&& (AbProfile[temp] != 'D'))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[temp]);
delay_ms(2000);
printf("Message to %s: POWER OFF%c", AbName[temp], CtrlZ);
StringBuilder();
temp1 = 0;
while ((strstr(ReceiveString, "OK") == NULL) && (strstr(ReceiveString, "ERROR") == NULL) && (temp1 < SMS_TIMEOUT))
{
temp1++;
StringBuilder();
delay_ms(1000);
}
}
}
SendingPOWOFF = 1;
}
}
GR_Off();
GSMStatus = 0;
}
else
{
EconoMode = 0;
SMSorDTMFEconoMode = 0;
SendingPOWOFF = 0;
}
if (PowerCorrect == 1)
if (temp <= ACC_CORRECT)
setbit(PORTB, CHARG);
else
clrbit(PORTB, CHARG);
else
clrbit(PORTB, CHARG);
SetActiveUart(UART_1);
delay_ms(2000);
if ((PINA & (1<<VDET)) > 0)
{
PowerCorrect = 1;
if ((AbRecReadComplete) && (GSMStatus == 2) && (Sending220VON == 0)) "220V ON"
{
for (temp = 0; temp < MAX_AB_NUMBER; temp++)
{
if ((strncmp(AbName[temp], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[temp], "##", sizeof("##")) != 0)
&& (AbProfile[temp] != 'D'))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[temp]);
delay_ms(2000);
printf("Message to %s: 220V ON%c", AbName[temp], CtrlZ);
delay_ms(4000);
StringBuilder();
}
}
Sending220VOFF = 0;
Sending220VON = 1;
}
}
else
{
PowerCorrect = 0;
if (AbRecReadComplete)
{
if (Sending220VOFF == 0)
{
for (temp = 0; temp < MAX_AB_NUMBER; temp++)
{
if ((strncmp(AbName[temp], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[temp], "##", sizeof("##")) != 0)
&& (AbProfile[temp] != 'D'))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[temp]);
delay_ms(2000);
printf("Message to %s: 220V OFF%c", AbName[temp], CtrlZ);
delay_ms(4000);
StringBuilder();
}
}
Sending220VOFF = 1;
Sending220VON = 0;
}
}
}
if (GSMStatus == 1)
{
printf("AT+CREG=1\n\r");
delay_ms(1000);
StringBuilder();
if (strstr(ReceiveString, "OK") != NULL)
GSMStatus = 2;
}
if (GSMStatus == 2)
{
printf("AT+CSQ\n\r");
delay_ms(1000);
StringBuilder();
strtok(ReceiveString, ",");
GSMSigStrength = StrToInt(ReceiveString);
if (GSMSigStrength <= 31)
{
GSMSigStrength /= 6;
if (GSMSigStrength == 0) GSMSigStrength = 1;
}
else GSMSigStrength = 1;
}
if ((EconoMode == 0) && (GSMStatus == 0))
{
SetActiveUart(UART_0);
printf("GSM ON attempt\n\r");
SetActiveUart(UART_1);
GR_On();
printf("AT\n\r");
delay_ms(1000);
StringBuilder();
if (strstr(ReceiveString, "OK") != NULL)
{
printf("ATE=1\n\r");
delay_ms(500);
printf("AT*E2RS232=2\n\r");
delay_ms(500);
printf("AT+CLIP=1\n\r");
delay_ms(500);
printf("AT+CMEE=1\n\r");
delay_ms(500);
printf("AT+CSDH=1\n\r");
delay_ms(500);
printf("AT+CMGF=1\n\r");
delay_ms(500);
printf("AT*E2SSN\n\r");
delay_ms(2000);
StringBuilder();
if (strstr(ReceiveString, "ERROR") == NULL)
{
GSMStatus = 1;
SetActiveUart(UART_0);
printf("GR Init OK.\n\r");
SetActiveUart(UART_1);
}
else
{
if (SIMNum == 0)
{
SIMNum = 1;
setbit(PORTC, SIMSW);
}
else
{
SIMNum = 0;
clrbit(PORTC, SIMSW);
}
}
}
}}
void GR_On(void)
{
clrbit(PORTG, nGSMPOW);
clrbit(PORTD,PON);
delay_ms(3000);
setbit(PORTD,PON);
delay_ms(4000);
}
void GR_Off(void)
{
clrbit(PORTD,PON);
delay_ms(3000);
setbit(PORTD,PON);
delay_ms(4000);
setbit(PORTG, nGSMPOW);
GSMStatus = 0;
}
void StringBuilder(void)
{
signed char IncomChar = 0;
int StringPoint = 0;
ReceiveString[0] = 0;
while ((IncomChar = ReadData()) != -1)
{
if (IncomChar > 20)
{
SetActiveUart(UART_0);
printf("%c", IncomChar);
SetActiveUart(UART_1);
ReceiveString[StringPoint] = IncomChar;
ReceiveString[StringPoint+1] = 0;
StringPoint++;
}
}
SetActiveUart(UART_0);
printf("\n\r");
SetActiveUart(UART_1);
}
int StrToInt (char* InputStr)
{
int ReturnValue = 0;
unsigned char StrCount = 0;
for (; StrCount <= strlen(InputStr); StrCount++)
if (isdigit(InputStr[StrCount]))
ReturnValue = 10*ReturnValue + (InputStr[StrCount] - 48);
return ReturnValue;
}
char ReadAbRecords(void)
{
char RecCount = 0;
char CharCount = 0;
char QuotesCount = 0;
char InNumCount = 0;
char InRecCount = 0;
char StarPos = 0;
char ServiceName [MAX_NAME_LENGTH+1];
char ServiceNum [SERVICE_NUM_LENGTH+1];
if (GSMStatus == 0) return 0;
else
{
for (RecCount = 0; RecCount < MAX_AB_NUMBER; RecCount++)
{
printf("AT+CPBR=%d\n\r", RecCount+1);
delay_ms(2000);
StringBuilder();
if (strstr(ReceiveString, "OK") != NULL)
{
QuotesCount = 0;
InNumCount = 0;
InRecCount = 0;
AbNumber[RecCount][0] = 0;
AbRecord[RecCount][0] = 0;
AbName [RecCount][0] = 0;
AbPass [RecCount][0] = 0;
AbPass [RecCount][3] = 0;
for (CharCount = 0; CharCount < strlen(ReceiveString); CharCount++)
{
if (QuotesCount == 1)
{
if (ReceiveString[CharCount] != '"')
{
AbNumber[RecCount][InNumCount] = ReceiveString[CharCount];
AbNumber[RecCount][InNumCount+1] = 0;
}
SetActiveUart(UART_0);
if (ReceiveString[CharCount] != '"') printf("N%c ", AbNumber[RecCount][InNumCount]);
SetActiveUart(UART_1);
if (InNumCount == MAX_NUMBER_LENGTH)
{
IncorrectAb = RecCount + 1;
return 0;
}
InNumCount++;
} if (QuotesCount == 3)
{
if (ReceiveString[CharCount] != '"')
{
AbRecord[RecCount][InRecCount] = ReceiveString[CharCount];
AbRecord[RecCount][InRecCount+1] = 0;
}
SetActiveUart(UART_0);
if (ReceiveString[CharCount] != '"') printf("R%c ", AbRecord[RecCount][InRecCount]);
SetActiveUart(UART_1);
if (InRecCount == MAX_RECORD_LENGTH)
{
IncorrectAb = RecCount + 1;
return 0;
}
InRecCount++;
} if (ReceiveString[CharCount] == '"')
{
QuotesCount++;
}
}
SetActiveUart(UART_0);
printf ("%d Number is %s\n\r", RecCount+1, AbNumber[RecCount]);
printf ("%d Record is %s\n\r", RecCount+1, AbRecord[RecCount]);
SetActiveUart(UART_1);
StarPos = strcspn(AbRecord[RecCount], "*");
strncpy( AbName[RecCount], AbRecord[RecCount], StarPos);
SetActiveUart(UART_0);
printf ("%d Name is %s\n\r", RecCount+1, AbName[RecCount]);
SetActiveUart(UART_1);
if (strncmp(AbName[RecCount], "##", sizeof("##")) == 0) AbActive[RecCount] = 0;
else
{
AbActive[RecCount] = 1;
AbPass[RecCount][0] = AbRecord[RecCount][StarPos+1];
AbPass[RecCount][1] = AbRecord[RecCount][StarPos+2];
AbPass[RecCount][2] = AbRecord[RecCount][StarPos+3];
if (strncmp(AbName[RecCount], "GUEST", sizeof("GUEST")) == 0)
{
GuestPass[0] = AbPass[RecCount][0];
GuestPass[1] = AbPass[RecCount][1];
GuestPass[2] = AbPass[RecCount][2];
GuestPass[3] = 0;
}
SetActiveUart(UART_0);
printf ("%d UPass is %s\n\r", RecCount+1, AbPass[RecCount]);
SetActiveUart(UART_1);
AbProfile[RecCount] = AbRecord[RecCount][StarPos+4];
AbCallTime[RecCount] = AbRecord[RecCount][StarPos+5];
AbCallNum[RecCount] = AbRecord[RecCount][StarPos+6]-48;
AbExtService[RecCount] = AbRecord[RecCount][StarPos+7];
SetActiveUart(UART_0);
printf ("%d UProf is %c\n\r", RecCount+1, AbProfile[RecCount]);
printf ("%d UOCT is %c\n\r", RecCount+1, AbCallTime[RecCount]);
printf ("%d UCA is %c\n\r", RecCount+1, AbCallNum[RecCount]);
printf ("%d UES is %c\n\r", RecCount+1, AbExtService[RecCount]);
SetActiveUart(UART_1);
if (AbRecord[RecCount][StarPos+8] != '*')
{
IncorrectAb = RecCount + 1;
return 0;
} } SetActiveUart(UART_0);
printf ("%d UA is %d\n\r", RecCount+1, AbActive[RecCount]);
SetActiveUart(UART_1);
} else
{
IncorrectAb = RecCount + 1;
return 0;
} }
printf("AT+CPBR=6\n\r");
delay_ms(2000);
StringBuilder();
if (strstr(ReceiveString, "OK") != NULL)
{
SetActiveUart(UART_0);
printf("SA OK\n\r");
SetActiveUart(UART_1);
} else
{
SetActiveUart(UART_0);
printf("SA Error\n\r");
SetActiveUart(UART_1);
IncorrectAb = RecCount + 1;
return 0;
}
QuotesCount = 0;
InNumCount = 0;
InRecCount = 0;
for (CharCount = 0; CharCount < strlen(ReceiveString); CharCount++)
{
if (QuotesCount == 1)
{
if (ReceiveString[CharCount] != '"')
{
ServiceNum[InNumCount] = ReceiveString[CharCount];
ServiceNum[InNumCount+1] = 0;
}
SetActiveUart(UART_0);
if (ReceiveString[CharCount] != '"') printf("SNum%c ", ServiceNum[InNumCount]);
SetActiveUart(UART_1);
if (InNumCount == SERVICE_NUM_LENGTH+1)
{
IncorrectAb = RecCount + 1;
return 0;
}
InNumCount++;
} if (QuotesCount == 3)
{
if (ReceiveString[CharCount] != '"')
{
ServiceName[InRecCount] = ReceiveString[CharCount];
ServiceName[InRecCount+1] = 0;
}
SetActiveUart(UART_0);
if (ReceiveString[CharCount] != '"') printf("SRec%c ", AbRecord[RecCount][InRecCount]);
SetActiveUart(UART_1);
if (InRecCount == MAX_RECORD_LENGTH)
{
IncorrectAb = RecCount + 1;
return 0;
}
InRecCount++;
} if (ReceiveString[CharCount] == '"')
QuotesCount++;
}
SetActiveUart(UART_0);
printf ("SN is %s\n\r", ServiceNum);
printf ("SR is %s\n\r", ServiceName);
SetActiveUart(UART_1);
if (!((strncmp(ServiceName, "Service", sizeof("Service")) == 0)
|| (strncmp(ServiceName, "SERVICE", sizeof("SERVICE")) == 0)
|| (strncmp(ServiceName, "service", sizeof("service")) == 0)))
{
IncorrectAb = RecCount + 1;
return 0;
}
if (isdigit(ServiceNum[0]))
{
DelayGuardOnTime = ServiceNum[0] - 48;
SetActiveUart(UART_0);
printf ("DGOnT = %d m\n\r", DelayGuardOnTime);
SetActiveUart(UART_1);
}
else
{
IncorrectAb = RecCount + 1;
return 0;
}
if (isdigit(ServiceNum[1]))
{
DelayGuardOffTime = 10*(ServiceNum[1] - 48);
SetActiveUart(UART_0);
printf ("DGOT = %d s\n\r", DelayGuardOffTime);
SetActiveUart(UART_1);
}
else
{
IncorrectAb = RecCount + 1;
return 0;
}
if ((isdigit(ServiceNum[2])) && ((ServiceNum[2]=='0') || (ServiceNum[2]=='1')))
{
iButtonUse = ServiceNum[2] - 48;
SetActiveUart(UART_0);
printf ("iBU = %d\n\r", iButtonUse);
SetActiveUart(UART_1);
}
else
{
IncorrectAb = RecCount + 1;
return 0;
}
if (isdigit(ServiceNum[3]))
{
LockOpenTime = ServiceNum[3] - 48;
SetActiveUart(UART_0);
printf ("LOT = %d second(s)\n\r", LockOpenTime);
SetActiveUart(UART_1);
}
else
{
IncorrectAb = RecCount + 1;
return 0;
}
if (isdigit(ServiceNum[4]))
{
SirenSingTime = 10*(ServiceNum[4] - 48);
SetActiveUart(UART_0);
printf ("SST = %d seconds\n\r", SirenSingTime);
SetActiveUart(UART_1);
}
else
{
IncorrectAb = RecCount + 1;
return 0;
}
} SetActiveUart(UART_0);
printf("End of AB\n\r");
SetActiveUart(UART_1);
IncorrectAb = 0;
return 1;
}
void iButtonUpdate (void)
{
if ((PINA & (1<<JIBP)) == 0)
{
iButtonMode = 1;
}
else if ((PINA & (1<<JIBM)) == 0)
{
iButtonMode = 2;
}
else
{
iButtonMode = 0;
}
}
unsigned char iButtonKeyScan(void)
{
unsigned char uidCounter;
SetActiveUart(UART_0);
ds1990a_init();
if ((CRC8(uidDS, 7) == uidDS[7]) && (uidDS[0] == DS1990A_ID))
for (uidCounter = 0; uidCounter <= CurrentKeys; uidCounter++)
if ((uidDS[0] == ibKeys[uidCounter][0]) && (uidDS[1] == ibKeys[uidCounter][1])
&& (uidDS[2] == ibKeys[uidCounter][2]) && (uidDS[3] == ibKeys[uidCounter][3])
&& (uidDS[4] == ibKeys[uidCounter][4]) && (uidDS[5] == ibKeys[uidCounter][5])
&& (uidDS[6] == ibKeys[uidCounter][6]))
{
return 1;
}
SetActiveUart(UART_1);
return 0;
}
void iButtonNewKeysSearch(void)
{
SetActiveUart(UART_0);
setbit(PORTC, GRDLED);
ds1990a_init();
RepeatedKey = 0;
if ((CRC8(uidDS, 7) == uidDS[7]) && (uidDS[0] == DS1990A_ID))
{
for (temp = 0; temp <= CurrentKeys; temp++)
if (((uidDS[0] == ibKeys[temp][0]) && (uidDS[1] == ibKeys[temp][1])
&& (uidDS[2] == ibKeys[temp][2]) && (uidDS[3] == ibKeys[temp][3])
&& (uidDS[4] == ibKeys[temp][4]) && (uidDS[5] == ibKeys[temp][5])
&& (uidDS[6] == ibKeys[temp][6])) || (CurrentKeys == MAX_IB_KEYS))
RepeatedKey = 1;
if (RepeatedKey == 0)
{
for (temp1 = 0; temp1 <= 7; temp1++)
ibKeys[CurrentKeys][temp1] = uidDS[temp1];
CurrentKeys++;
clrbit(PORTC, GRDLED);
delay_ms(3000);
setbit(PORTC, GRDLED);
}
else
{
for (temp1 = 0; temp1 <= 4*5; temp1++)
{
delay_ms(250);
invbit(PORTC, GRDLED);
}
}
}
clrbit(PORTC, GRDLED);
SetActiveUart(UART_1);
}
void iButtonKeysErase(void)
{
SetActiveUart(UART_0);
setbit(PORTC, GRDLED);
if (CurrentKeys != 0)
{
for (temp = 0; temp <= 4*3; temp++)
{
delay_ms(250);
invbit(PORTC, GRDLED);
}
CurrentKeys = 0;
for (temp = 0; temp < MAX_IB_KEYS; temp++)
for (temp1 = 0; temp1 < IB_KEY_LENGTH; temp1++)
ibKeys[temp][temp1] = 0xFF;
}
clrbit(PORTC, GRDLED);
SetActiveUart(UART_1);
}
static unsigned int BufferCounter = 0;
static unsigned int PageCounter = 0;
#define DF_RESET (1<<nFRES)
#define DF_MM_RD 0xD2
#define DF_BUF_1_RD 0xD4
#define DF_BUF_2_RD 0xD6
#define DF_MP_B1_XFER 0x53
#define DF_MP_B2_XFER 0x55
#define DF_SREG 0xD7
volatile unsigned char Timer1OverCount = 0;
#pragma vector = TIMER1_OVF_vect
__interrupt void OutVoiceSample(void)
{
Timer1OverCount++;
if (Timer1OverCount == 2)
{
Timer1OverCount = 0;
ACSR |= T1_OVF;
}
}
void DF_WriteSPI(unsigned char data)
{
SPDR = data;
while (!(SPSR & 0x80));
}
unsigned char DF_Status(void)
{
DF_WriteSPI(DF_SREG);
DF_WriteSPI(0xFF);
return SPDR;
}
unsigned char DF_Ready(void)
{
return (DF_Status() & (1<<DF_BIT_READY));
}
void DF_MainMemoryToSpeaker(unsigned int Page)
{
unsigned long IntroAddress;
unsigned char dummy = 0;
unsigned int StartAddress = 0;
clrbit(PORTG, nFCS);
DF_WriteSPI(DF_MM_RD);
DF_WriteSPI((char)(Page >> 7));
DF_WriteSPI((char)(Page << 1)|(StartAddress >> 8));
DF_WriteSPI((char)(StartAddress));
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
for(IntroAddress = 0; IntroAddress < MAX_BUFFER; IntroAddress++)
{
while(!(ACSR&T1_OVF));
DF_WriteSPI(0xFF);
dummy = SPDR;
OCR1B = dummy;
ACSR &= (~T1_OVF);
}
setbit(PORTG, nFCS);
}
void DF_PagesToSpeaker(unsigned int StartPage, unsigned int EndPage)
{
unsigned int CurrentPage;
SPCR = 0x5C;
TCCR1A = 0x21;
TCNT1 = 0x00;
TIFR = 0x04;
setbit(TIMSK, TOIE1);
TCCR1B = 0x01;
OCR1B = 0x00;
for (CurrentPage = StartPage; CurrentPage <= EndPage; CurrentPage++)
DF_MainMemoryToSpeaker(CurrentPage);
clrbit(TIMSK, TOIE1);
TCCR1B = 0x00;
SPCR = 0x00;}
void GuardIn (unsigned char InGuardSource)
{
SetActiveUart(UART_0);
printf("Guard ON attempt ");
if ((LoopTest() == 1)
&& (GuardSource == 0))
switch (InGuardSource)
{
case GS_SWITCHER:
printf("Switcher\n\r");
Loop1Violation = 0;
Loop2Violation = 0;
Loop3Violation = 0;
TotalHackLoops = 0;
GuardSource = 1;
AttemptInError = 0;
clrbit(PORTC, GRDLED);
PreparationGuardTime = DelayGuardOnTime*60;
break;
case GS_IBUTTON:
printf("iButton\n\r");
Loop1Violation = 0;
Loop2Violation = 0;
Loop3Violation = 0;
TotalHackLoops = 0;
GuardSource = 4;
AttemptInError = 0;
clrbit(PORTC, GRDLED);
PreparationGuardTime = DelayGuardOnTime*60;
break;
case GS_SMS:
printf("SMS\n\r");
Loop1Violation = 0;
Loop2Violation = 0;
Loop3Violation = 0;
TotalHackLoops = 0;
GuardSource = 2;
AttemptInError = 0;
clrbit(PORTC, GRDLED);
PreparationGuardTime = DelayGuardOnTime*60;
break;
case GS_DTMF:
printf("DTMF\n\r");
Loop1Violation = 0;
Loop2Violation = 0;
Loop3Violation = 0;
TotalHackLoops = 0;
GuardSource = 3;
AttemptInError = 0;
clrbit(PORTC, GRDLED);
PreparationGuardTime = DelayGuardOnTime*60;
break;
}
else
{
printf("- Warning: attempt fail. Source = %d\n\r", InGuardSource);
}
if ((LoopTest() == 0)
&& (GuardSource == 0))
AttemptInError = 1;
SetActiveUart(UART_1);
}
void GuardOut (unsigned char OutGuardSource)
{
SetActiveUart(UART_0);
printf("Guard OFF attempt ");
if (GuardSource != 0)
switch (OutGuardSource)
{
case GS_SWITCHER:
if (iButtonUse == 0)
{
if (GuardSource == GS_SWITCHER)
{
printf("Switcher\n\r");
TmLockOpenTime = LockOpenTime;
printf("Lock open!\n\r");
GuardSource = 0;
}
else
{
printf(":Warning. Switcher is not allowed\n\r");
}
}
else
{
printf(":Warning. iButtonUse = 1\n\r");
}
break;
case GS_IBUTTON:
printf("iButton\n\r");
TmLockOpenTime = LockOpenTime;
GuardSource = 0;
break;
case GS_SMS:
if (GuardSource != GS_SWITCHER)
{
GuardSource = 0;
printf("SMS\n\r");
TmLockOpenTime = LockOpenTime;
}
else
printf ("- SMS ERROR\n\r");
break;
case GS_DTMF:
if (GuardSource != GS_SWITCHER)
{
GuardSource = 0;
printf("DTMF\n\r");
TmLockOpenTime = LockOpenTime;
}
else
printf ("- DTMF ERROR\n\r");
break;
default:
printf("- ERROR: unknown source !!!\n\r");
}
else
printf("- Warning: attempt fail. Source = %d\n\r", OutGuardSource);
SetActiveUart(UART_1);
}
void LoopsRead (void)
{
unsigned int LoopCode = 0;
if (Loop1On > 0)
{
LoopCode = ReadADC(LIN1);
if (LoopCode < LO_LOOP_LIMIT)
Loop1Status = 2;
else if ((LoopCode > LO_LOOP_LIMIT) && (LoopCode < HI_LOOP_LIMIT))
Loop1Status = 0;
else
Loop1Status = 1;
}
if (Loop2On > 0)
{
LoopCode = ReadADC(LIN2);
if (LoopCode < LO_LOOP_LIMIT)
Loop2Status = 2;
else if ((LoopCode > LO_LOOP_LIMIT) && (LoopCode < HI_LOOP_LIMIT))
Loop2Status = 0;
else
Loop2Status = 1;
}
if (Loop3On > 0)
{
LoopCode = ReadADC(LIN3);
if (LoopCode < LO_LOOP_LIMIT)
Loop3Status = 2;
else if ((LoopCode > LO_LOOP_LIMIT) && (LoopCode < HI_LOOP_LIMIT))
Loop3Status = 0;
else
Loop3Status = 1;
}}
#define INTRO_START 0
#define INTRO_START_DF INTRO_START*(SOUND_FACTOR/MAX_BUFFER)
#define INTRO_END 4
#define INTRO_END_DF INTRO_END*(SOUND_FACTOR/MAX_BUFFER)
void GuardReaxion(void)
{
unsigned char ReaxCount = 0;
unsigned char ReaxTemp = 0;
char HackLoops [sizeof(" 1 2 3")] = "";
unsigned char AbCallConfirm[MAX_AB_NUMBER];
unsigned char ReaxCallTimeout = 0;
unsigned char ReaxCallNum = 0;
unsigned char ReaxVoiceAttempt = 0;
#define VOICE_ATTEMPT_NUM 7
TmSirenSingTime = SirenSingTime;
if (Loop1Violation == 1)
strncpy(HackLoops, " 1", sizeof(" 1"));
if (Loop2Violation == 1)
strncpy(HackLoops, " 2", sizeof(" 2"));
if (Loop3Violation == 1)
strncpy(HackLoops, " 3", sizeof(" 3"));
for (ReaxCount = 0; ReaxCount < MAX_AB_NUMBER; ReaxCount++)
{
if ((strncmp(AbName[ReaxCount], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[ReaxCount], "##", sizeof("##")) != 0)
&& ((AbProfile[ReaxCount] == 'A') || (AbProfile[ReaxCount] == 'C') || (AbExtService[ReaxCount] == 1)))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[ReaxCount]);
delay_ms(2000);
printf("Message to %s: ALARM! LINE(S)%s.%c", AbName[ReaxCount], HackLoops, CtrlZ);
StringBuilder();
ReaxTemp = 0;
while ((strstr(ReceiveString, "OK") == NULL) && (strstr(ReceiveString, "ERROR") == NULL) && (ReaxTemp < 10))
{
ReaxTemp++;
StringBuilder();
delay_ms(1000);
}
}
}
for (ReaxCount = 0; ReaxCount < MAX_AB_NUMBER; ReaxCount++)
{
if ((strncmp(AbName[ReaxCount], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[ReaxCount], "##", sizeof("##")) != 0)
&& ((AbProfile[ReaxCount] == 'A') || (AbProfile[ReaxCount] == 'B')))
{
clrbit(TIMSK, TOIE0);
setbit(PORTC, GSMLED);
ReaxCallNum = AbCallNum[ReaxCount];
while (ReaxCallNum != 0)
{
switch (AbCallTime[ReaxCount])
{
case '0':
ReaxCallTimeout = 30;
break;
case '1':
ReaxCallTimeout = 60;
break;
case '2':
ReaxCallTimeout = 120;
break;
default:
ReaxCallTimeout = 40;
break;
}
AbCallConfirm[ReaxCount] = 0;
printf("ATD %s;\n\r", AbNumber[ReaxCount]);
while(ReaxCallTimeout != 0)
{
StringBuilder();
delay_ms(1000);
printf("AT+CPAS=1\n\r");
if (strstr(ReceiveString, "130") != NULL)
{
DTMFPassPos = 0;
DTMFPassBuf[0] = 0;
while ((ReaxVoiceAttempt++ < VOICE_ATTEMPT_NUM) && (DTMFPassBuf[0] != DTMF_SHARP))
{
DTMFPassPos = 0;
DTMFPassBuf[0] = 0;
DF_PagesToSpeaker(INTRO_START_DF, INTRO_END_DF);
if (Loop1Violation == 1)
DF_PagesToSpeaker(ODIN_START_DF, ODIN_END_DF);
if (Loop2Violation == 1)
DF_PagesToSpeaker(DVA_START_DF, DVA_END_DF);
if (Loop3Violation == 1)
DF_PagesToSpeaker(TRI_START_DF, TRI_END_DF);
}
AbCallConfirm[ReaxCount] = 1;
ReaxCallNum = 0;
break;
}
if (strstr(ReceiveString, "129") != NULL)
break;
ReaxCallTimeout--;
}
StringBuilder();
printf("ATH\n\r");
delay_ms(2000);
StringBuilder();
if (ReaxCallNum != 0) ReaxCallNum--;
}
clrbit(PORTC, GSMLED);
setbit(TIMSK, TOIE0);
}
}
for (ReaxCount = 0; ReaxCount < MAX_AB_NUMBER; ReaxCount++)
{
if ((strncmp(AbName[ReaxCount], "GUEST", sizeof("GUEST")) != 0)
&& (strncmp(AbName[ReaxCount], "##", sizeof("##")) != 0)
&& ((AbProfile[ReaxCount] == 'B') && (AbCallConfirm[ReaxCount] == 0)))
{
printf("AT+CMGS=\"%s\"\n\r", AbNumber[ReaxCount]);
delay_ms(2000);
printf("Message to %s: ALARM! LINE(S)%s.%c", AbName[ReaxCount], HackLoops, CtrlZ);
StringBuilder();
ReaxTemp = 0;
while ((strstr(ReceiveString, "OK") == NULL) && (strstr(ReceiveString, "ERROR") == NULL) && (ReaxTemp < 10))
{
ReaxTemp++;
StringBuilder();
delay_ms(1000);
}
}
}
}
#endif
portdefines.h
#define POUT2 0
#define JIBP 1
#define JIBM 2
#define IBTN 3
#define VDET 4
#define SCK 1
#define SI 2
#define SO 3
#define PWDN 4
#define CHARG 5
#define SPKOUT 6
#define POUT1 7
#define SIMSW 0
#define EXTKEY 1
#define EGRDLED 2
#define EGSMLED 3
#define EPOWLED 4
#define GRDLED 5
#define GSMLED 6
#define POWLED 7
#define PON 0
#define PDTR 1 // DTR
#define PRD 2 // RXD1
#define PTD 3 // TXD1
#define PRTS 4 // RTS
#define PCTS 5 // CTS
#define PDCD 6 // DCD
#define PRI 7 // RI
#define RXD0 0
#define TXD0 1
#define DTQ1 2
#define DTQ2 3
#define STD 4
#define DTQ3 5
#define DTQ4 6
#define CON 7
#define AFMS 0
#define LIN1 1
#define LIN2 2
#define LIN3 3
#define VBAT 4
#define J1 5
#define J2 6
#define J3 7
#define nFCS 0 // Chip Select AT45DB041B
#define nFRES 1 // Reset AT45DB041B
#define nGSMPOW 2
#define K2 3
#define K1 4
main.c
#define MasterClock 8000000
#include "main.h"
main ()
{
BeginInit();
ClearRxBuffer();
asm("SEI");
SetActiveUart(UART_0);
printf(">>\n\r");
SetActiveUart(UART_1);
SIMNum = 0;
while (1)
{
SystemUpdate();
iButtonUpdate();
LoopsRead();
LoopTest();
while(iButtonMode != 0)
{
iButtonUpdate();
if (iButtonMode == 1)
iButtonNewKeysSearch();
if (iButtonMode == 2)
iButtonKeysErase();
}
if ((!AbRecReadComplete) && (GSMStatus !=0))
{
AbRecReadComplete = ReadAbRecords();
SIMFault = AbRecReadComplete;
}
if ((LoopViolation == 1) && (GuardSource != 0) && (TmGuardOffTimeout == 0))
{
GuardReaxion();
LoopViolation = 0;
PreparationGuardTime = REPEAT_GUARD_TIME;
} }}
sound.c
#ifndef _sound_rec_
#define _sound_rec_
#include <iom128.h>
#include "portdefines.h"
#include "kedahm.h"
#define T1_OVF 0x01
#define CLEARED 0x02
#define DF_BIT_READY 7
#define MAX_BUFFER 264
#define MAX_PAGE 2048
static unsigned int BufferCounter = 0;
static unsigned int PageCounter = 0;
#define DF_RESET (1<<nFRES) // nFRES - portdefines.h
#define DF_BUF_1 0x00
#define DF_BUF_2 0x01
#define DF_BUF_1_WR 0x84
#define DF_BUF_2_WR 0x87
#define DF_BUF_1_RD 0x54
#define DF_BUF_2_RD 0x56
#define DF_B1_MP_PROG_ERASE 0x83
#define DF_B2_MP_PROG_ERASE 0x86
#define DF_B1_MP_PROG_NO_ERASE 0x88
#define DF_B2_MP_PROG_NO_ERASE 0x89
#define DF_MP_PROG_B1 0x82
#define DF_MP_PROG_B2 0x85
#define DF_AUTO_PAGE_REWR_B1 0x58
#define DF_AUTO_PAGE_REWR_B2 0x59
#define DF_MP_B1_COMP 0x60
#define DF_MP_B2_COMP 0x61
#define DF_MP_B1_XFER 0x53
#define DF_MP_B2_XFER 0x55
#define DF_SREG 0x57
#define DF_MP_READ 0x52
#define PAGE_ERASE 0x81
#define BLOCK_ERASE 0x50
#define TRUE 0xff
#define FALSE 0x00
#define QTR_MICRO_SECOND 2
#define HALF_MICROSECOND 4
#define ONE_MICROSECOND 8
#define TWO_MICROSECONDS 16
#define THREE_MICROSECONDS 24
#define FIVE_MICROSECONDS 40
#define TEN_MICROSECONDS 80
#define TWENTY_MICROSECONDS 160
void DF_WriteSPI(unsigned char data);
unsigned char DF_Status( void );
unsigned char DF_Ready( void );
void DF_NextPageToNextBuffer (unsigned char active_buffer, unsigned int page_counter);
void DF_Playback (void);
void DF_ActiveBufferToSpeaker (unsigned char active_buffer);
volatile unsigned char wait = 0;
void DF_WriteSPI (unsigned char data)
{
SPDR = data;
while (!(SPSR & (1<<SPIF)));
}
unsigned char DF_Status(void)
{
clrbit(PORTG, nFCS);
DF_WriteSPI(DF_SREG);
DF_WriteSPI(0xFF);
setbit(PORTG, nFCS); return SPDR;
}
unsigned char DF_Ready(void){
return (DF_Status() & (1<<DF_BIT_READY));
}
void DF_Playback(void)
{
unsigned int PageCounter = 0;
unsigned char ActiveBuffer = 1;
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<CPOL)|(1<<CPHA);
DF_NextPageToNextBuffer(ActiveBuffer, PageCounter);
while(DF_Ready == 0);
while (PageCounter < MAX_PAGE-1)
{
PageCounter++;
DF_NextPageToNextBuffer(ActiveBuffer, PageCounter);
DF_ActiveBufferToSpeaker (ActiveBuffer);
if (ActiveBuffer == 1)
{
ActiveBuffer++;
}
else
{
ActiveBuffer--;
}
}
SPCR = 0x00;}
void DF_NextPageToNextBuffer (unsigned char active_buffer, unsigned int page_counter)
{
while(DF_Ready == 0);
clrbit(PORTG, nFCS);
if (active_buffer == 1)
DF_WriteSPI(DF_MP_B1_XFER);
else DF_WriteSPI(DF_MP_B2_XFER);
DF_WriteSPI((char)(page_counter >> 6));
DF_WriteSPI((char)(page_counter << 2));
DF_WriteSPI(0x00);
setbit(PORTG, nFCS);}
void DF_ActiveBufferToSpeaker(unsigned char active_buffer)
{
unsigned int buffer_counter = MAX_BUFFER;
clrbit(PORTG, nFCS);
if (active_buffer == 1)
DF_WriteSPI(DF_BUF_1_RD);
else DF_WriteSPI(DF_BUF_2_RD);
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
DF_WriteSPI(0x00);
do
{
DF_WriteSPI(0xFF);
SetActiveUart(UART_0);
printf(">%c", SPDR);
SetActiveUart(UART_1);
}
while (--buffer_counter);
setbit(PORTG, nFCS);}
#endif
|
|