ДП_поясняк (1231259), страница 12
Текст из файла (страница 12)
T_DATE.day=buf;buf=0;
uart_write(" enter mounth ");
buf=10*CharToInt(uart_getc());
buf=buf+CharToInt(uart_getc());
T_DATE.mounth=buf;buf=0;
uart_write(" enter year ");
buf=10*CharToInt(uart_getc());
buf=buf+CharToInt(uart_getc());
T_DATE.year=buf; buf=0;
uart_write (" data set complete !");
TD_buf=1; break;
case 'T':uart_write(" enter sec ");
buf=10*CharToInt(uart_getc());
buf=buf+CharToInt(uart_getc());
T_TIME.sec=buf;buf=0;
uart_write(" enter min ");
buf=10*CharToInt(uart_getc());
buf=buf+CharToInt(uart_getc());
T_TIME.min=buf;buf=0;
uart_write(" enter hour ");
buf=10*CharToInt(uart_getc());
buf=buf+CharToInt(uart_getc());
T_TIME.hour=buf;
buf=0;
uart_write (" time set complete !"); break;}
LCD_date();}
//---------вывод даты-------------------------------------------------------------
void LCD_date(void){
if (T_DATE.day == 0){
LCDstring("No date ",20,1);}else{
sprintf(str_d,"%02u",T_DATE.day);
LCDstring(str_d,20,1);LCDstring(".",22,1);
sprintf(str_d,"%02u",T_DATE.mounth);
LCDstring(str_d,23,1);
LCDstring(".",25,1);
sprintf(str_d,"%u",T_DATE.year);
LCDstring(str_d,26,1);}}
void LCD_start(void){
LCDclear();
LCDstring("Rezhim 0",0,0);
LCDstring("Offline ",20,0);
T_DATE.day=16 ;T_DATE.mounth = 04;
T_DATE.year = 16;LCD_date();}
//---Осн.программа-------------------------------------------------
int main(void){
MCUinit();LCDinit();
LCDstring("Start Init",0,0);
unsigned char temp;int i;
PORTC=_BV(CS)|_BV(DO)|_BV(DI);//|_BV(WP)|_BV(INS); //Инициализация портов
DDRC=_BV(CS)|_BV(DI)|_BV(CLK);
/*temp=sd_card_init();
if (temp==0x00) {LCDstring("SD init OK ",20,0);}
else{LCDstring("SD init fail ",20,0);}*/
_delay_ms(1000);
unsigned char ret;
i2c_init();
ret = i2c_start(ctrl_R);
//MRF_init();_delay_ms(100);
LCDstring("MRF init OK ",20,0);
//-----------------для юарт-------uart_init(4800);
_delay_ms(500);LCDstring("UART init OK ",20,0);
_delay_ms(500);TD_buf=1;_delay_ms(500);
LCD_start();TIMER2_init();
StartConvAdc();sei();
while(1){
ADC_data[8]= i2c_readAck();
if ( (UCSRA & (1<<RXC)) ){
T_temp=UDR;
switch (T_temp){
case 'C':conf();T_I=0;TIMER2_init();
T_temp=0; break;}}
//------------------time-------------------------------
if (T_I==T_max){
//LCDclear();
//Rezhim_i(m_count);
//Rezhim_Out(R_out);
//LCD_date();
A_DC();
T_I=0;
//----увеличение времени-----
T_TIME.sec++;
if (T_TIME.sec > 59){
T_TIME.sec=0;
T_TIME.min++;
if (T_TIME.min> 59){
T_TIME.min=0;
T_TIME.hour++;
if (T_TIME.hour > 24){
T_TIME.hour=0;}}}
//------LCD_time
sprintf(str_t,"%02u",T_TIME.hour);
LCDstring(str_t,30,1);
LCDstring(":",32,1);
sprintf(str_t,"%02u",T_TIME.min);
LCDstring(str_t,33,1);
LCDstring(":",35,1);
sprintf(str_t,"%02u",T_TIME.sec);
LCDstring(str_t,36,1);
//----Отправка по Zigbee
/*if (MRF){
unsigned char MRF_buf;
MRF_write_l(0x000, 0x03); //
MRF_write_l(0x001, 0x05); //
MRF_write_l(0x002, 0x22);
MRF_write_l(0x003, 0x00);
MRF_write_l(0x004, 0x01);
MRF_write_l(0x005, ADC_data[m_count] ); //
MRF_write_s(MRF_TXNMTRIG, 0x01);
MRF_buf=MRF_read_l(0x304);}*/}
/-------проверяем нажатие кнопки--------------------------
//-------Кнопка режимов------------
if (Key_press1==1){
Key_press1=0;
Rezhim_i(m_count);
// выбор режима}
if ( ((PIND &(1<<3))==0) ){
Key_press1=1;
if (m_count ==3){
m_count=0;}
else {
m_count++;}
while ( ((PIND & (1<<3)) == 0) ){
//ждем пока отпустят кнопк}
//-------Кнопка вкл/выкл передачи по сетям и на комп
if ( ((PIND &(1<<2))==0) ){
Key_press2=1;
if (R_out == 2){R_out=0;}else { R_out++;}
while ( ((PIND & (1<<2))==0) ){
if (Key_press2==1){
Key_press2=0;
Rezhim_Out(R_out);
// выбор режима отправки}
//-------нажатие настройки--------------
//}}}
Приложение Б
Листинг программы управления устройством сбора информации
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AfPortControls, AfViewers, AfDataTerminal,
AfDataDispatcher, AfComPort, Buttons, ExtCtrls, ComCtrls, Menus, ToolWin,
ImgList;
type
TForm1 = class(TForm)
AfDataDispatcher1: TAfDataDispatcher;AfDataTerminal1: TAfDataTerminal;
Button1: TButton;SpeedButton1: TSpeedButton;
Com: TAfComPort;SBar: TStatusBar;
Button2: TButton;SpeedButton2: TSpeedButton;
MainMenu1: TMainMenu;N1: TMenuItem;
N2: TMenuItem;N3: TMenuItem;COM1: TMenuItem;
CP1: TMenuItem;Main1: TMenuItem;
COM2: TMenuItem;CP2: TMenuItem;
N4: TMenuItem;N5: TMenuItem;
GroupBox1: TGroupBox;Button3: TButton;
Button4: TButton;GroupBox2: TGroupBox;
Button5: TButton;GroupBox3: TGroupBox;
Edit1: TEdit;Zigbee1: TMenuItem;
ZigBee2: TMenuItem;CP3: TMenuItem;
GroupBox4: TGroupBox;Button6: TButton;
Button7: TButton;ToolBar1: TToolBar;
ToolButton1: TToolButton;ToolButton2: TToolButton;
COM3: TMenuItem;ImageList1: TImageList;
Panel2: TPanel;ToolButton3: TToolButton;
ToolButton4: TToolButton;GroupBox5: TGroupBox;
GroupBox6: TGroupBox;GroupBox7: TGroupBox;
StaticText1: TStaticText;StaticText2: TStaticText;
StaticText3: TStaticText;StaticText4: TStaticText;
StaticText5: TStaticText;StaticText6: TStaticText;
StaticText7: TStaticText;StaticText8: TStaticText;
ToolBar2: TToolBar;ToolButton5: TToolButton;
ToolButton6: TToolButton;ToolButton7: TToolButton;
ToolButton8: TToolButton;ToolButton9: TToolButton;
ToolButton10: TToolButton;ToolButton11: TToolButton;
ToolButton12: TToolButton;Panel3: TPanel;
Panel4: TPanel;Panel5: TPanel;
Panel6: TPanel;Panel7: TPanel;
Panel8: TPanel;Panel9: TPanel;
Panel10: TPanel;StaticText10: TStaticText;
StaticText11: TStaticText;StaticText12: TStaticText;
StaticText13: TStaticText;StaticText14: TStaticText;
StaticText15: TStaticText;StaticText16: TStaticText;
Panel11: TPanel;Edit2: TEdit;
Memo1: TMemo;Timer1: TTimer;Button8: TButton;
procedure ComPortOpen(Sender: TObject);
procedure ComPortClose(Sender: TObject);
procedure AfDataDispatcher1DataReceived(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure COM2Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure CP1Click(Sender: TObject);
procedure Zigbee1Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
buf:byte;
br:string ;
NPort:Word;
ab: array[1..1024] of byte; //приемный буфер
in_buf:string;
i:integer;
bs:string;
ADC0,ADC1,ADC2,ADC3,ADC4,ADC5,ADC6,ADC7,ADC8:string;
implementation
uses ComConf, MRFbufSruct, Unit2, Unit3;
{$R *.dfm}
procedure TForm1.ComPortOpen(Sender: TObject);
begin
Speedbutton1.Enabled:=true;
sbar.Panels[0].Text:='СOM: подключен'
end;
procedure TForm1.ComPortClose(Sender: TObject);
begin
Speedbutton1.Enabled:=false;
sbar.Panels[0].Text:='СOM: отключен'
end;
procedure TForm1.AfDataDispatcher1DataReceived(Sender: TObject);
var
s:string;
begin
s:= AfDataDispatcher1.ReadString;
if copy(s,1,2)='S ' then begin
bs:=in_buf;
memo1.Lines.add(bs);
in_buf:=s;
end
else
in_buf:=in_buf+s;
s:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
if com.Active then
begin
com.close;
button1.Caption:='COM Start';
end
else
begin
com.Open;
button1.Caption:='COM Stop';
end;
except
showmessage('Ошибка подключения');
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
com.WriteString('l');
sbar.Panels[1].Text:='Чтение: по длинному';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
com.WriteString('s');
sbar.Panels[1].Text:='Чтение: по короткому';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
sbar.Panels[2].Text:='Aдрес:'+Edit1.Text;
com.WriteString(Edit1.Text);
end;
procedure TForm1.COM2Click(Sender: TObject);
begin
Com_conf.ShowModal;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
Mrf_buf_struct.Show;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
try
com.WriteString(Edit2.Text);
except
end;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
if Toolbutton5.ImageIndex=5 then
Toolbutton5.ImageIndex:=4
else
Toolbutton5.ImageIndex:=5;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
type
TIntegerSet = set of 0..SizeOf(byte)*8 - 1;
var
buf:byte;
begin
if not (bs ='') then begin















