📄 main.c~
字号:
/*****************************************************
Project : PT2272 series Simulator
Version : 1.0
Date : 2006/10/28
Author : behzad khazama
Company : www.khazama.com
Comments: finally implemented at 1385/08/06 -- 04:43AM IRAN - SABZEVAR
Chip type : ATmega32
Clock frequency : 12.000000 MHz
Some Important Notice about Calibration.
with a 2.2Mega OHM Oscillator Calibrator risistor
used with PT2262(Pin 15,16) ,
-> Timer1 overflow must trigger every 120us.
see Timer1 overflow routin for more.
THIS Project is AS-IS and FREE to USE and FREE to Modify.
BUT Please put my sites link into your projects that use this code.
and finally I Implement this code very rush and it maybe have some BUGs.
SO : ANY BUGs OR SUGGESTIONs ARE WELCOME.
Pin connections:
INPUT Code(insted DIN of PT2272) is "INT0 PORTD.2"
LCD 2*16 -> PORTA as discribed on CodevisionAvr
Fell Free and contact me by :
my contact Number : +98-09155714862
or via eMail : behzad@khazama.com
*****************************************************/
#include <mega32.h>
#include <delay.h>
// Standard Input/Output functions
#include <stdio.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
// Declare your global variables and FUNCTIONS here
extern void init(void);
unsigned char edge=1;
unsigned int HTime=0,LTime=0 ;
unsigned long Tm=0;
unsigned char bufer[13];
unsigned char Tmp[24];
unsigned char DetectTruePacket=0;
#pragma warn-
void FinalAnalyse(void){
unsigned char i=0;
for(i=0;i<12;i++){
if (Tmp[i*2]==0 && Tmp[(i*2)+1]==0){
bufer[i]='0';
}
else if(Tmp[i*2]==1 && Tmp[(i*2)+1]==1){
bufer[i]='1';
}
else{
bufer[i]='F';
}
};
bufer[12]=0; // terminate string
}
#pragma warn+
unsigned char isSync(void){
if (HTime<LTime)
if(HTime>13 && HTime<30)
if(LTime>570 && LTime<700)
return(1);
return(0);
}
unsigned char isZero(void){
if (HTime<LTime)
if(HTime>13 && HTime<30)
if(LTime>50 && LTime<70)
return(1);
return(0);
}
unsigned char isOne(void){
if (HTime>LTime)
if(LTime>13 && LTime<30)
if(HTime>50 && HTime<70)
return(1);
return(0);
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
/* TCNT1 = 0xFF9B that mean 65535-100
so this routin will trigger every 120us on 12MHZ.
if your project is using different clock rate
u must modify TCNT1 rigisters to project work fine.*/
TCNT1H=0xFF;
TCNT1L=0x9B;
Tm++;
}
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
static unsigned char bitCnt=0;
if(edge>0){
LTime=Tm;
Tm=0;
MCUCR = 2; // Set interrupt on falling edge
edge = 0;
if(isSync()){
if(bitCnt==24){
FinalAnalyse() ;
DetectTruePacket=1;
};
bitCnt=0;
} else if(isZero()){
Tmp[bitCnt++]=0;
} else if(isOne()){
Tmp[bitCnt++]=1;
} else{
bitCnt=0;
}
}else{
HTime=Tm;
Tm=0;
MCUCR = 3; // Set interrupt on rising edge
edge = 1;
};
}
void main(void)
{
init();
lcd_init(16);
#asm("sei")
while (1)
{
if(DetectTruePacket){
lcd_gotoxy(0,0);
lcd_puts(bufer);
DetectTruePacket=0;
};
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -