📄 main.i
字号:
/*****************************************************
Project : PT2272 series Simulator
Version : 1.0
Date : 2006/10/28
Author : behzad khazama
Company : www.khazama.com
Comments: finally implemented at 1385/07/07 -- 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
*****************************************************/
// CodeVisionAVR C Compiler
// (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega32
#pragma used+
sfrb TWBR=0;
sfrb TWSR=1;
sfrb TWAR=2;
sfrb TWDR=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4; // 16 bit access
sfrb ADCSRA=6;
sfrb ADCSR=6; // for compatibility with older code
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRRL=9;
sfrb UCSRB=0xa;
sfrb UCSRA=0xb;
sfrb UDR=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e; // 16 bit access
sfrb UBRRH=0x20;
sfrb UCSRC=0X20;
sfrb WDTCR=0x21;
sfrb ASSR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28; // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a; // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c; // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb SFIOR=0x30;
sfrb OSCCAL=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TWCR=0x36;
sfrb SPMCR=0x37;
sfrb TIFR=0x38;
sfrb TIMSK=0x39;
sfrb GIFR=0x3a;
sfrb GICR=0x3b;
sfrb OCR0=0X3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-
// Interrupt vectors definitions
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
// Standard Input/Output functions
// CodeVisionAVR C Compiler
// (C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
// Prototypes for standard I/O functions
// CodeVisionAVR C Compiler
// (C) 1998-2002 Pavel Haiduc, HP InfoTech S.R.L.
// Variable length argument list macros
typedef char *va_list;
#pragma used+
char getchar(void);
void putchar(char c);
void puts(char *str);
void putsf(char flash *str);
char *gets(char *str,unsigned int len);
void printf(char flash *fmtstr,...);
void sprintf(char *str, char flash *fmtstr,...);
void vprintf (char flash * fmtstr, va_list argptr);
void vsprintf (char *str, char flash * fmtstr, va_list argptr);
signed char scanf(char flash *fmtstr,...);
signed char sscanf(char *str, char flash *fmtstr,...);
#pragma used-
#pragma library stdio.lib
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
/* LCD driver routines
CodeVisionAVR C Compiler
(C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
BEFORE #include -ING THIS FILE YOU
MUST DECLARE THE I/O ADDRESS OF THE
DATA REGISTER OF THE PORT AT WHICH
THE LCD IS CONNECTED!
EXAMPLE FOR PORTB:
#asm
.equ __lcd_port=0x18
#endasm
#include <lcd.h>
*/
#pragma used+
void _lcd_ready(void);
void _lcd_write_data(unsigned char data);
// write a byte to the LCD character generator or display RAM
void lcd_write_byte(unsigned char addr, unsigned char data);
// read a byte from the LCD character generator or display RAM
unsigned char lcd_read_byte(unsigned char addr);
// set the LCD display position x=0..39 y=0..3
void lcd_gotoxy(unsigned char x, unsigned char y);
// clear the LCD
void lcd_clear(void);
void lcd_putchar(char c);
// write the string str located in SRAM to the LCD
void lcd_puts(char *str);
// write the string str located in FLASH to the LCD
void lcd_putsf(char flash *str);
// initialize the LCD controller
unsigned char lcd_init(unsigned char lcd_columns);
#pragma used-
#pragma library lcd.lib
// 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 [10] 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 [2] 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 + -