⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 这我用delphi编写的AVR串口通信工具串口通信原代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:

procedure TForm1.Label4MouseLeave(Sender: TObject);
begin
  Label4.Font.Style:=Label4.Font.Style-[fsUnderline];
  Label4.Font.Color :=clBlack;
  Label4.Cursor :=crDefault;
end;

procedure TForm1.Label4Click(Sender: TObject);
begin
  ShellExecute(Handle,nil,'http://www.avrarm.com','','',SW_SHOW);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Form1.Caption ='AVR 串口开发工具 V1.0' then
     Form1.Caption :='http://www.avrarm.com'
  else if Form1.Caption ='http://www.avrarm.com' then
     Form1.Caption :='AVR USART TOOL V1.0'
  else
     Form1.Caption :='AVR 串口开发工具 V1.0';
end;

procedure TForm1.ComboBox3Change(Sender: TObject);
var
  kkk   : string;
begin
  Memo1.Clear ;
  //kkk:=ComboBox3.Items.ValueFromIndex[ComboBox3.ItemIndex];
  kkk:=ComboBox3.Text ;
  if (kkk ='ATMega64') or (kkk ='ATMega128')then
  begin
     //CheckBox3.Enabled := true;
     //CheckBox4.Enabled := true;
     //CheckBox6.Enabled := true;
     //CheckBox8.Enabled := true;
     //CheckBox10.Enabled := true;
     //CheckBox12.Enabled := true;

     CheckBox3.Checked := true;
     CheckBox10.Checked := true;

     UCSR0C :=UCSR0C and 127;

     Form1.Width :=673;
     Memo1.Left :=440;
     GroupBox3.Left :=440;
     GroupBox2.Left :=224;
     BitBtn1.Left :=464;
     BitBtn2.Left :=560;
     Label4.Left :=168;
    // Form1.Position :=poScreenCenter;
  end
  else
  begin
     Form1.Width :=457;
     Memo1.Left :=224;
     GroupBox3.Left :=224;
     GroupBox2.Left :=528;
     BitBtn1.Left :=248;
     BitBtn2.Left :=344;
     Label4.Left :=72;

     UCSR0C :=UCSR0C or 128;
    // Form1.Position :=poDesktopCenter;
     
     //CheckBox3.Enabled := true;
     //CheckBox4.Enabled := false;
     //CheckBox6.Enabled := false;
     //CheckBox8.Enabled := false;
     //CheckBox10.Enabled := false;
     //CheckBox12.Enabled := false;

     CheckBox3.Checked := true;
     CheckBox10.Checked := false;
   //  CheckBox5.Checked := false;
     //CheckBox6.Checked := false;
   //  CheckBox7.Checked := false;
     //CheckBox8.Checked := false;
     //CheckBox10.Checked := false;
     //CheckBox12.Checked := false;
  end;
end;

procedure TForm1.BitBtn1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  BitBtn1.Font.Color :=clBlack;
end;

procedure TForm1.BitBtn1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  BitBtn1.Font.Color :=clBlue;
end;

procedure TForm1.ComboBox4Change(Sender: TObject);
var
  Number :Integer;
begin
  Number:= ComboBox4.ItemIndex;
  case Number  of
    0 :
    begin
      UCSR0B :=UCSR0B and 251;
      UCSR0C :=UCSR0C and 253;
      UCSR0C :=UCSR0C and 251;
    end;
    1 :
    begin
      UCSR0B :=UCSR0B and 251;
      UCSR0C :=UCSR0C or 2;
      UCSR0C :=UCSR0C and 251;
    end;
    2 :
    begin
      UCSR0B :=UCSR0B and 251;
      UCSR0C :=UCSR0C and 253;
      UCSR0C :=UCSR0C or 4;
    end;
    3 :
    begin
      UCSR0B :=UCSR0B and 251;
      UCSR0C :=UCSR0C or 2;
      UCSR0C :=UCSR0C or 4;
    end;
    4 :
    begin
      UCSR0B :=UCSR0B or 4;
      UCSR0C :=UCSR0C or 2;
      UCSR0C :=UCSR0C or 4;
    end;
    else
    begin
      UCSR0B :=UCSR0B or 4;
      UCSR0C :=UCSR0C and 253;
      UCSR0C :=UCSR0C and 251;
    end;
  end;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked =true then
     UCSR0C :=UCSR0C or 8          //2位停止位
  else
     UCSR0C :=UCSR0C and 247;
end;

procedure TForm1.ComboBox6Change(Sender: TObject);
begin
  Baud1 :=StrToInt(ComboBox6.Text);
end;

procedure TForm1.ComboBox7Change(Sender: TObject);
var
  Number :Integer;
begin
  Number:= ComboBox7.ItemIndex;
  case Number  of
    0 :
    begin
      UCSR1B :=UCSR1B and 251;
      UCSR1C :=UCSR1C and 253;
      UCSR1C :=UCSR1C and 251;
    end;
    1 :
    begin
      UCSR1B :=UCSR1B and 251;
      UCSR1C :=UCSR1C or 2;
      UCSR1C :=UCSR1C and 251;
    end;
    2 :
    begin
      UCSR1B :=UCSR1B and 251;
      UCSR1C :=UCSR1C and 253;
      UCSR1C :=UCSR1C or 4;
    end;
    3 :
    begin
      UCSR1B :=UCSR1B and 251;
      UCSR1C :=UCSR1C or 2;
      UCSR1C :=UCSR1C or 4;
    end;
    4 :
    begin
      UCSR1B :=UCSR1B or 4;
      UCSR1C :=UCSR1C or 2;
      UCSR1C :=UCSR1C or 4;
    end;
    else
    begin
      UCSR1B :=UCSR1B or 4;
      UCSR1C :=UCSR1C and 253;
      UCSR1C :=UCSR1C and 251;
    end;
  end;
end;

procedure TForm1.CheckBox13Click(Sender: TObject);
begin
  if CheckBox13.Checked =true then
  begin
     U2X1   :=1;
     UCSR1A :=UCSR1A or 2;          //倍速
  end
  else
  begin
     U2X1   :=2;
     UCSR1A :=UCSR1A and 253;
  end;
end;

procedure TForm1.CheckBox12Click(Sender: TObject);
begin
  if CheckBox12.Checked =true then
     UCSR1C :=UCSR1C or 8          //2位停止位
  else
     UCSR1C :=UCSR1C and 247;
end;

procedure TForm1.CheckBox5Click(Sender: TObject);
begin
  if CheckBox5.Checked =true then
     UCSR0B :=UCSR0B or 16          //接受使能
  else
     UCSR0B :=UCSR0B and 239;
end;

procedure TForm1.CheckBox14Click(Sender: TObject);
begin
  if CheckBox14.Checked =true then
     UCSR1B :=UCSR1B or 16          //接受使能
  else
     UCSR1B :=UCSR1B and 239;
end;

procedure TForm1.CheckBox7Click(Sender: TObject);
begin
  if CheckBox5.Checked =true then
     UCSR0B :=UCSR0B or 8          //发送使能
  else
     UCSR0B :=UCSR0B and 247;
end;

procedure TForm1.CheckBox16Click(Sender: TObject);
begin
  if CheckBox16.Checked =true then
     UCSR1B :=UCSR1B or 8          //发送使能
  else
     UCSR1B :=UCSR1B and 247;
end;

procedure TForm1.CheckBox18Click(Sender: TObject);
begin
  if CheckBox18.Checked =true then
     UCSR1B :=UCSR1B or 128         //接收中断使能
  else
     UCSR1B :=UCSR1B and 127;
end;

procedure TForm1.CheckBox19Click(Sender: TObject);
begin
  if CheckBox19.Checked =true then
     UCSR1B :=UCSR1B or 64         //发送中断使能
  else
     UCSR1B :=UCSR1B and 191;
end;

procedure TForm1.CheckBox11Click(Sender: TObject);
begin
  if CheckBox11.Checked =true then
     UCSR0B :=UCSR0B or 64         //发送中断使能
  else
     UCSR0B :=UCSR0B and 191;
end;

procedure TForm1.CheckBox9Click(Sender: TObject);
begin
  if CheckBox9.Checked =true then
     UCSR0B :=UCSR0B or 128         //接收中断使能
  else
     UCSR0B :=UCSR0B and 127;
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
begin
  if CheckBox8.Checked =true then
     UCSR0B :=UCSR0B or 32         //数据寄存器空中断使能
  else
     UCSR0B :=UCSR0B and 223;
end;

procedure TForm1.CheckBox17Click(Sender: TObject);
begin
  if CheckBox17.Checked =true then
     UCSR1B :=UCSR1B or 32         //数据寄存器空中断使能
  else
     UCSR1B :=UCSR1B and 223;
end;

procedure TForm1.CheckBox6Click(Sender: TObject);
begin
  if CheckBox6.Checked =true then
     UCSR0A :=UCSR0A or 1         //多处理器通讯模式使能
  else
     UCSR0A :=UCSR0A and 254;
end;

procedure TForm1.CheckBox15Click(Sender: TObject);
begin
  if CheckBox15.Checked =true then
     UCSR1A :=UCSR1A or 1         //多处理器通讯模式使能
  else
     UCSR1A :=UCSR1A and 254;
end;

procedure TForm1.CheckBox21Click(Sender: TObject);
begin
  if CheckBox21.Checked =true then
  begin
     UCSR0C :=UCSR0C or 64;          //通讯模式选择
     CheckBox4.Enabled := true;
     CheckBox6.Enabled := false;
     CheckBox6.Checked := false;
     CheckBox6Click(Sender);
  end
  else
  begin
     UCSR0C :=UCSR0C and 191;
     CheckBox4.Enabled := false;
     CheckBox4.Checked := false;
     CheckBox4Click(Sender);
     CheckBox6.Enabled := true;
  end;
end;

procedure TForm1.CheckBox22Click(Sender: TObject);
begin
  if CheckBox22.Checked =true then
  begin
     UCSR1C :=UCSR1C or 64;          //通讯模式选择
     CheckBox20.Enabled := true;
     CheckBox15.Enabled := false;
     CheckBox15.Checked := false;
     CheckBox15Click(Sender);
  end   
  else
  begin
     UCSR1C :=UCSR1C and 191;
     CheckBox20.Enabled := false;
     CheckBox20.Checked := false;
     CheckBox20Click(Sender);
     CheckBox15.Enabled := true;
  end;   
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin
  if CheckBox4.Checked =true then
     UCSR0C :=UCSR0C or 1          //时钟极性选择
  else
     UCSR0C :=UCSR0C and 254;
end;

procedure TForm1.CheckBox20Click(Sender: TObject);
begin
  if CheckBox20.Checked =true then
     UCSR1C :=UCSR1C or 1          //时钟极性选择
  else
     UCSR1C :=UCSR1C and 254;
end;

procedure TForm1.ComboBox5Change(Sender: TObject);
var
  Number :Integer;
begin
  Number:= ComboBox5.ItemIndex;
  case Number  of
    0 :
    begin
      UCSR0C :=UCSR0C and 239;
      UCSR0C :=UCSR0C and 223;
    end;
    1 :
    begin
      UCSR0C :=UCSR0C or 16;
      UCSR0C :=UCSR0C and 223;
    end;
    2 :
    begin
      UCSR0C :=UCSR0C and 239;
      UCSR0C :=UCSR0C or 32;
    end;
    3 :
    begin
      UCSR0C :=UCSR0C or 16;
      UCSR0C :=UCSR0C or 32;
    end;
  end;
end;

procedure TForm1.ComboBox8Change(Sender: TObject);
var
  Number :Integer;
begin
  Number:= ComboBox8.ItemIndex;
  case Number  of
    0 :
    begin
      UCSR1C :=UCSR1C and 239;
      UCSR1C :=UCSR1C and 223;
    end;
    1 :
    begin
      UCSR1C :=UCSR1C or 16;
      UCSR1C :=UCSR1C and 223;
    end;
    2 :
    begin
      UCSR1C :=UCSR1C and 239;
      UCSR1C :=UCSR1C or 32;
    end;
    3 :
    begin
      UCSR1C :=UCSR1C or 16;
      UCSR1C :=UCSR1C or 32;
    end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -