📄 频率发生器__.c
字号:
#include <mega8.h>
#include <LCD_Interface.h>
#include <LCDv3.h>
#include <USART.h>
#include <Delay.h>
#include <Types.h>
#include <IRv2.h>
#define nil 0
#include "Config.h"
#include "LCD_Interface.c"
#ifndef _LCDINTERFACEC_INCLUDED_
#define _LCDINTERFACEC_INCLUDED_
void LCD_WriteCaption(unsigned char ParamCaptionID,unsigned char ValueCaptionID);
void LCD_Interface_Init()
{
DDRD|=((1<<PD4)|(1<<PD6)|(1<<PD7));
PORTD&=~((1<<PD4)|(1<<PD6)|(1<<PD7));
}
void LCD_Interface_PutData(unsigned char Data)
{
DDRC=0x3F;
DDRB|=(1<<PB7)|(1<<PB6);
PORTC=0x3F&Data;
PORTB=(PINB&0x3F)|(((1<<PB7)|(1<<PB6))&Data);
}
void LCD_Interface_RS(unsigned char State)
{
if (State)
PORTD|=(1<<PD7);
else
PORTD&=~(1<<PD7);
}
void LCD_Interface_RW(unsigned char State)
{
if (State)
PORTD|=(1<<PD6);
else
PORTD&=~(1<<PD6);
}
void LCD_Interface_E(unsigned char State)
{
if (State)
PORTD|=(1<<PD4);
else
PORTD&=~(1<<PD4);
}
unsigned char LCD_Interface_Busy(void)
{
DDRC=0x00;
DDRB&=~((1<<PB7)|(1<<PB6));
#asm
nop
#endasm
return (PINB&(1<<PB7));
}
unsigned char LCD_Interface_GetData(void)
{
//DDRC=0x00;
//DDRB&=~((1<<PB7)|(1<<PB6));
return ((PINB&(1<<PB6))|(PINC&0x3F));
}
void LCD_Delay(unsigned int Value)
{
unsigned int i;
for (i=0;i<Value;i++)
#asm
nop
#endasm
}
#endif
#include "Input.c"
#include "LCD_Interface.c"
#ifndef _LCDINTERFACEC_INCLUDED_
#define _LCDINTERFACEC_INCLUDED_
void LCD_WriteCaption(unsigned char ParamCaptionID,unsigned char ValueCaptionID);
void LCD_Interface_Init()
{
DDRD|=((1<<PD4)|(1<<PD6)|(1<<PD7));
PORTD&=~((1<<PD4)|(1<<PD6)|(1<<PD7));
}
void LCD_Interface_PutData(unsigned char Data)
{
DDRC=0x3F;
DDRB|=(1<<PB7)|(1<<PB6);
PORTC=0x3F&Data;
PORTB=(PINB&0x3F)|(((1<<PB7)|(1<<PB6))&Data);
}
void LCD_Interface_RS(unsigned char State)
{
if (State)
PORTD|=(1<<PD7);
else
PORTD&=~(1<<PD7);
}
void LCD_Interface_RW(unsigned char State)
{
if (State)
PORTD|=(1<<PD6);
else
PORTD&=~(1<<PD6);
}
void LCD_Interface_E(unsigned char State)
{
if (State)
PORTD|=(1<<PD4);
else
PORTD&=~(1<<PD4);
}
unsigned char LCD_Interface_Busy(void)
{
DDRC=0x00;
DDRB&=~((1<<PB7)|(1<<PB6));
#asm
nop
#endasm
return (PINB&(1<<PB7));
}
unsigned char LCD_Interface_GetData(void)
{
//DDRC=0x00;
//DDRB&=~((1<<PB7)|(1<<PB6));
return ((PINB&(1<<PB6))|(PINC&0x3F));
}
void LCD_Delay(unsigned int Value)
{
unsigned int i;
for (i=0;i<Value;i++)
#asm
nop
#endasm
}
#endif
#ifndef _INPUT_INCLUDED_
#define BT_NUM_0 0x10
#define BT_NUM_1 0x11
#define BT_NUM_2 0x12
#define BT_NUM_3 0x13
#define BT_NUM_4 0x14
#define BT_NUM_5 0x15
#define BT_NUM_6 0x16
#define BT_NUM_7 0x17
#define BT_NUM_8 0x18
#define BT_NUM_9 0x19
#define BT_SHIFT 0x1A
#define BT_LEFT 0x1B
#define BT_RIGHT 0x1C
#define BT_UP 0x1D
#define BT_DOWN 0x1E
#define BT_APPLY 0x1F
#define BT_POWER 0x20
#define _INPUT_INCLUDED_
unsigned char GetKey(void)
{
unsigned char IRCmd[4];
unsigned char IRKeyPress=0;
unsigned char i;
if (IR_GetBuffer(IRCmd,&IRKeyPress))
{
if ((~IRCmd[0]==IRCmd[1])&&(~IRCmd[2]==IRCmd[3])&&(IRKeyPress>0))
{
SOUND_START; //Sound Start
for (i=0;i<17;i++)
{
if (IRCmd[2]==mConfig[i])
{
IRKeyPress = i + 0x10;
break;
}
}
}
IR_Complete();
}
return IRKeyPress;
}
void GetInput(unsigned char ParamCaptionID,unsigned char ValueCaptionID,unsigned char *vByte,unsigned int *vInt)
{
unsigned char Buffer[4];
unsigned char Pos;
unsigned char Pos2=0;
unsigned char *Result;
unsigned char Key;
unsigned char Size;
unsigned char i;
unsigned char Shift=0;
delay_ms(10);
SOUND_STOP;
if (vByte==0)
{
Result=(unsigned char *)vInt;
Buffer[0]=Result[1];
Result[1]=Result[0];
Result[0]=Buffer[0];
Size=2;
}
else
{
Result=vByte;
Size=1;
}
LCD_WriteCaption(ParamCaptionID,ValueCaptionID);
LCD_PutStrF("=");
Pos=LCD_Position();
Key=1;
while (Key!=BT_APPLY)
{
if (Key!=0)
{
BinToHex(Result,Buffer,Size);
for (i=0;i<Size*2;i++)
{
if (Pos2==i)
{
WriteCGRAM(Buffer[i],i+4,0x80);
}
else
{
WriteCGRAM(Buffer[i],i+4,0);
}
}
LCD_Ctrl(LCD_SET_DDRAM|Pos);
for (i=0;i<Size*2;i++)
{
LCD_Write(i+4);
}
}
Key=GetKey();
if (Key==BT_LEFT)
{
Pos2-=(Pos2>0);
Shift=0;
}
else if (Key==BT_RIGHT)
{
Pos2+=(Pos2<(Size*2-1));
Shift=0;
}
else if (Key==BT_UP)
{
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=Result[Buffer[0]]&Buffer[1];
if (Buffer[2]<Buffer[1]) Buffer[2]+=(0x11&Buffer[1]);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Shift=0;
}
else if (Key==BT_DOWN)
{
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=Result[Buffer[0]]&Buffer[1];
if (Buffer[2]>0) Buffer[2]-=(0x11&Buffer[1]);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Shift=0;
}
else if ((Key>=BT_NUM_0)&&(Key<=BT_NUM_9))
{
if ((Key>=BT_NUM_0)&&(Key<=BT_NUM_5)&&(Shift==1))
{
Buffer[3]=Key-0x06;
}
else
{
Buffer[3]=Key-0x10;
}
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=(Buffer[3])<<(4-(Pos2 - Buffer[0]*2)*4);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Pos2+=(Pos2<(Size*2-1));
Shift=0;
}
else if (Key==BT_APPLY)
{
if (Size==2)
{
Buffer[0]=Result[1];
Result[1]=Result[0];
Result[0]=Buffer[0];
}
}
else if (Key==BT_SHIFT)
{
Shift=1;
}
if (Key!=0)
{
delay_ms(10);
SOUND_STOP;
}
}
}
void GetInputBoolean(unsigned char ParamCaptionID,unsigned char ValueCaptionID,unsigned char *vByte,unsigned char BitPos)
{
//unsigned char Buffer[4];
unsigned char Pos;
unsigned char Result;
unsigned char Key;
delay_ms(10);
SOUND_STOP;
Result=*vByte;
LCD_WriteCaption(ParamCaptionID,ValueCaptionID);
LCD_PutStrF("=");
Pos=LCD_Position();
Key=1;
WriteCGRAM('0',2,0x80);
WriteCGRAM('1',3,0x80);
while (Key!=BT_APPLY)
{
if (Key!=0)
{
LCD_Ctrl(LCD_SET_DDRAM|Pos);
LCD_Write(2+((Result>>BitPos)&0x01));
}
Key=GetKey();
if ((Key==BT_NUM_1)||(Key==BT_UP))
{
Result|=(1<<BitPos);
}
else if ((Key==BT_NUM_0)||(Key==BT_DOWN))
{
Result&=(~(1<<BitPos));
}
else if (Key==BT_APPLY)
{
*vByte=Result;
}
else if (Key==BT_LEFT)
{
Key=BT_APPLY;
}
if (Key!=0)
{
delay_ms(10);
SOUND_STOP;
}
}
}
#endif
#include "Menu.h"
#include "Menu.c"
#include <LCDv3.h>
#include "Config.h"
#include "Menu.h"
#include "LCD_Interface.c"
#ifndef _LCDINTERFACEC_INCLUDED_
#define _LCDINTERFACEC_INCLUDED_
void LCD_WriteCaption(unsigned char ParamCaptionID,unsigned char ValueCaptionID);
void LCD_Interface_Init()
{
DDRD|=((1<<PD4)|(1<<PD6)|(1<<PD7));
PORTD&=~((1<<PD4)|(1<<PD6)|(1<<PD7));
}
void LCD_Interface_PutData(unsigned char Data)
{
DDRC=0x3F;
DDRB|=(1<<PB7)|(1<<PB6);
PORTC=0x3F&Data;
PORTB=(PINB&0x3F)|(((1<<PB7)|(1<<PB6))&Data);
}
void LCD_Interface_RS(unsigned char State)
{
if (State)
PORTD|=(1<<PD7);
else
PORTD&=~(1<<PD7);
}
void LCD_Interface_RW(unsigned char State)
{
if (State)
PORTD|=(1<<PD6);
else
PORTD&=~(1<<PD6);
}
void LCD_Interface_E(unsigned char State)
{
if (State)
PORTD|=(1<<PD4);
else
PORTD&=~(1<<PD4);
}
unsigned char LCD_Interface_Busy(void)
{
DDRC=0x00;
DDRB&=~((1<<PB7)|(1<<PB6));
#asm
nop
#endasm
return (PINB&(1<<PB7));
}
unsigned char LCD_Interface_GetData(void)
{
//DDRC=0x00;
//DDRB&=~((1<<PB7)|(1<<PB6));
return ((PINB&(1<<PB6))|(PINC&0x3F));
}
void LCD_Delay(unsigned int Value)
{
unsigned int i;
for (i=0;i<Value;i++)
#asm
nop
#endasm
}
#endif
#include "Input.c"
#include "LCD_Interface.c"
#ifndef _LCDINTERFACEC_INCLUDED_
#define _LCDINTERFACEC_INCLUDED_
void LCD_WriteCaption(unsigned char ParamCaptionID,unsigned char ValueCaptionID);
void LCD_Interface_Init()
{
DDRD|=((1<<PD4)|(1<<PD6)|(1<<PD7));
PORTD&=~((1<<PD4)|(1<<PD6)|(1<<PD7));
}
void LCD_Interface_PutData(unsigned char Data)
{
DDRC=0x3F;
DDRB|=(1<<PB7)|(1<<PB6);
PORTC=0x3F&Data;
PORTB=(PINB&0x3F)|(((1<<PB7)|(1<<PB6))&Data);
}
void LCD_Interface_RS(unsigned char State)
{
if (State)
PORTD|=(1<<PD7);
else
PORTD&=~(1<<PD7);
}
void LCD_Interface_RW(unsigned char State)
{
if (State)
PORTD|=(1<<PD6);
else
PORTD&=~(1<<PD6);
}
void LCD_Interface_E(unsigned char State)
{
if (State)
PORTD|=(1<<PD4);
else
PORTD&=~(1<<PD4);
}
unsigned char LCD_Interface_Busy(void)
{
DDRC=0x00;
DDRB&=~((1<<PB7)|(1<<PB6));
#asm
nop
#endasm
return (PINB&(1<<PB7));
}
unsigned char LCD_Interface_GetData(void)
{
//DDRC=0x00;
//DDRB&=~((1<<PB7)|(1<<PB6));
return ((PINB&(1<<PB6))|(PINC&0x3F));
}
void LCD_Delay(unsigned int Value)
{
unsigned int i;
for (i=0;i<Value;i++)
#asm
nop
#endasm
}
#endif
#ifndef _INPUT_INCLUDED_
#define BT_NUM_0 0x10
#define BT_NUM_1 0x11
#define BT_NUM_2 0x12
#define BT_NUM_3 0x13
#define BT_NUM_4 0x14
#define BT_NUM_5 0x15
#define BT_NUM_6 0x16
#define BT_NUM_7 0x17
#define BT_NUM_8 0x18
#define BT_NUM_9 0x19
#define BT_SHIFT 0x1A
#define BT_LEFT 0x1B
#define BT_RIGHT 0x1C
#define BT_UP 0x1D
#define BT_DOWN 0x1E
#define BT_APPLY 0x1F
#define BT_POWER 0x20
#define _INPUT_INCLUDED_
unsigned char GetKey(void)
{
unsigned char IRCmd[4];
unsigned char IRKeyPress=0;
unsigned char i;
if (IR_GetBuffer(IRCmd,&IRKeyPress))
{
if ((~IRCmd[0]==IRCmd[1])&&(~IRCmd[2]==IRCmd[3])&&(IRKeyPress>0))
{
SOUND_START; //Sound Start
for (i=0;i<17;i++)
{
if (IRCmd[2]==mConfig[i])
{
IRKeyPress = i + 0x10;
break;
}
}
}
IR_Complete();
}
return IRKeyPress;
}
void GetInput(unsigned char ParamCaptionID,unsigned char ValueCaptionID,unsigned char *vByte,unsigned int *vInt)
{
unsigned char Buffer[4];
unsigned char Pos;
unsigned char Pos2=0;
unsigned char *Result;
unsigned char Key;
unsigned char Size;
unsigned char i;
unsigned char Shift=0;
delay_ms(10);
SOUND_STOP;
if (vByte==0)
{
Result=(unsigned char *)vInt;
Buffer[0]=Result[1];
Result[1]=Result[0];
Result[0]=Buffer[0];
Size=2;
}
else
{
Result=vByte;
Size=1;
}
LCD_WriteCaption(ParamCaptionID,ValueCaptionID);
LCD_PutStrF("=");
Pos=LCD_Position();
Key=1;
while (Key!=BT_APPLY)
{
if (Key!=0)
{
BinToHex(Result,Buffer,Size);
for (i=0;i<Size*2;i++)
{
if (Pos2==i)
{
WriteCGRAM(Buffer[i],i+4,0x80);
}
else
{
WriteCGRAM(Buffer[i],i+4,0);
}
}
LCD_Ctrl(LCD_SET_DDRAM|Pos);
for (i=0;i<Size*2;i++)
{
LCD_Write(i+4);
}
}
Key=GetKey();
if (Key==BT_LEFT)
{
Pos2-=(Pos2>0);
Shift=0;
}
else if (Key==BT_RIGHT)
{
Pos2+=(Pos2<(Size*2-1));
Shift=0;
}
else if (Key==BT_UP)
{
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=Result[Buffer[0]]&Buffer[1];
if (Buffer[2]<Buffer[1]) Buffer[2]+=(0x11&Buffer[1]);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Shift=0;
}
else if (Key==BT_DOWN)
{
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=Result[Buffer[0]]&Buffer[1];
if (Buffer[2]>0) Buffer[2]-=(0x11&Buffer[1]);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Shift=0;
}
else if ((Key>=BT_NUM_0)&&(Key<=BT_NUM_9))
{
if ((Key>=BT_NUM_0)&&(Key<=BT_NUM_5)&&(Shift==1))
{
Buffer[3]=Key-0x06;
}
else
{
Buffer[3]=Key-0x10;
}
Buffer[0]=(Pos2>1);
Buffer[1]=0xF0>>((Pos2 - Buffer[0]*2)*4);
Buffer[2]=(Buffer[3])<<(4-(Pos2 - Buffer[0]*2)*4);
Result[Buffer[0]]=(Result[Buffer[0]]&(~Buffer[1]))|(Buffer[2]);
Pos2+=(Pos2<(Size*2-1));
Shift=0;
}
else if (Key==BT_APPLY)
{
if (Size==2)
{
Buffer[0]=Result[1];
Result[1]=Result[0];
Result[0]=Buffer[0];
}
}
else if (Key==BT_SHIFT)
{
Shift=1;
}
if (Key!=0)
{
delay_ms(10);
SOUND_STOP;
}
}
}
void GetInputBoolean(unsigned char ParamCaptionID,unsigned char ValueCaptionID,unsigned char *vByte,unsigned char BitPos)
{
//unsigned char Buffer[4];
unsigned char Pos;
unsigned char Result;
unsigned char Key;
delay_ms(10);
SOUND_STOP;
Result=*vByte;
LCD_WriteCaption(ParamCaptionID,ValueCaptionID);
LCD_PutStrF("=");
Pos=LCD_Position();
Key=1;
WriteCGRAM('0',2,0x80);
WriteCGRAM('1',3,0x80);
while (Key!=BT_APPLY)
{
if (Key!=0)
{
LCD_Ctrl(LCD_SET_DDRAM|Pos);
LCD_Write(2+((Result>>BitPos)&0x01));
}
Key=GetKey();
if ((Key==BT_NUM_1)||(Key==BT_UP))
{
Result|=(1<<BitPos);
}
else if ((Key==BT_NUM_0)||(Key==BT_DOWN))
{
Result&=(~(1<<BitPos));
}
else if (Key==BT_APPLY)
{
*vByte=Result;
}
else if (Key==BT_LEFT)
{
Key=BT_APPLY;
}
if (Key!=0)
{
delay_ms(10);
SOUND_STOP;
}
}
}
#endif
#define MENU_LINE 2
unsigned char MenuNo(unsigned char No)
{
if ((No>=0)&&(No<=9))
{
return No+'0';
}
else if ((No>=10)&&(No<=36))
{
return No-10+'A';
}
else
{
return '?';
}
}
void ChooseRadioMenu(unsigned char ParamCaptionID,unsigned char MenuDefineID,unsigned char *Value)
{
flash unsigned char *Caption;
flash unsigned char *pDefine;
unsigned char Key;
unsigned char Pos;
unsigned int TopMenuItem;
unsigned int CurrentMenuItem;
//unsigned char i;
unsigned char MenuCount;
delay_ms(10);
SOUND_STOP;
LCD_WriteCaption(ParamCaptionID,0);
Pos=LCD_Position()-1;
WriteCGRAM(0x82,1,0);
WriteCGRAM(0x83,2,0);
WriteCGRAM(0x84,3,0);
pDefine=SubMenuDefine+(unsigned int)2*(unsigned int)MenuDefineID;
MenuCount=pDefine[1];
TopMenuItem=pDefine[0];
CurrentMenuItem=*Value;
if (CurrentMenuItem>MenuCount-1)
{
CurrentMenuItem=MenuCount-1;
}
Key=1;
while (Key!=BT_APPLY)
{
if (Key!=0)
{
LCD_Ctrl(LCD_SET_DDRAM|Pos);
Caption=Menu+(CAPTION_LENGTH+2)*(TopMenuItem+CurrentMenuItem-1);
if (CurrentMenuItem==0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -