0% found this document useful (0 votes)
5 views5 pages

ATmega 2560 HMI Program Code

The document outlines a program for an HMI display using the ATmega 2560 microcontroller, configured for serial communication and ADC input. It includes variable initialization, input handling for adjusting parameters (Kv, Ma, Sc), and a main loop that processes user commands. The program allows for real-time updates and constraints on the parameter values within specified limits.

Uploaded by

yos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

ATmega 2560 HMI Program Code

The document outlines a program for an HMI display using the ATmega 2560 microcontroller, configured for serial communication and ADC input. It includes variable initialization, input handling for adjusting parameters (Kv, Ma, Sc), and a main loop that processes user commands. The program allows for real-time updates and constraints on the parameter values within specified limits.

Uploaded by

yos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM DISPLAY HMI ( ATMEGA 2560)

$regfile = "[Link]"

$crystal = 16000000

$hwstack = 40

$swstack = 16

$framesize = 32

$baud = 9600

$baud1 = 9600

'===============================================================================

Dim In_adc0 As Long , In_adc1 As Long , In_adc2 As Long

'----------------------------------------------------------

Dim In_s1 As String * 25 , Vir_in As Long

Dim In_s2 As Integer

Dim Kv As Long , Ma As Long , Sc As Long

Dim Vir_kv As Long , Vir_ma As Long , Vir_sc As Long

'--------------------------------------------

Config Portd = Output

Config Adc = Single , Prescaler = Auto

'--------------------------------------------

Open "COM1:" For Binary As #1

Open "COM2:" For Binary As #2

'--------------------------------------------

Enable Interrupts

Start Adc

'===============================================================================
main1

Main1:

Do

Vir_in = Ischarwaiting(#2)

If Vir_in = 1 Then
In_s1 = Waitkey(#2)

Print #1 , In_s1

End If

'===============================================================================

'------------------------------------------------------------ Kv +/- -----------

If In_s1 = "K" And Vir_in = 1 Then : Goto Kv_in : End If

If Kv < 40 Then : Kv = 40 : End If

If Kv > 125 Then : Kv = 125 : End If

'-------------------------------------------------------------------------------

'------------------------------------------------------------ mA +/- -----------

If In_s1 = "M" And Vir_in = 1 Then : Goto Ma_in : End If

If Ma < 40 Then : Ma = 40 : End If

If Ma > 200 Then : Ma = 200 : End If

'-------------------------------------------------------------------------------

'------------------------------------------------------------ Sec +/- -----------

If In_s1 = "S" And Vir_in = 1 Then : Goto Sec_in : End If

If Sc < 1 Then : Sc = 1 : End If

If Sc > 200 Then : Sc = 200 : End If

'-------------------------------------------------------------------------------

Print #2 , "[Link]=" ; Sc ; : Printbin #2 , 255 ; 255 ; 255

Print #2 , "[Link]=" ; Ma ; : Printbin #2 , 255 ; 255 ; 255

Print #2 , "[Link]=" ; Kv ; : Printbin #2 , 255 ; 255 ; 255

'Print #1 , "in=" ; In_s1 ; "=" ; Vir_in ; " "

Loop Until Vir_in = 27

Return

'=============================================================================== kv
in

Kv_in:

Do
'-------------------------------------

Vir_in = Ischarwaiting(#2)

If Vir_in = 1 Then

In_s1 = Waitkey(#2)

Print #1 , In_s1

End If

'------------------------------------

If In_s1 = "1" And Vir_in = 1 Then

Decr Kv

Goto Main1

End If

'---------------------------------------

If In_s1 = "2" And Vir_in = 1 Then

Incr Kv

Goto Main1

End If

Loop

Return

'===============================================================================
ma in

Ma_in:

Do

'-------------------------------------

Vir_in = Ischarwaiting(#2)

If Vir_in = 1 Then

In_s1 = Waitkey(#2)

Print #1 , In_s1

End If
'------------------------------------

If In_s1 = "1" And Vir_in = 1 Then

Decr Ma

Goto Main1

End If

'---------------------------------------

If In_s1 = "2" And Vir_in = 1 Then

Incr Ma

Goto Main1

End If

Loop

Return

'===============================================================================
sec in

Sec_in:

Do

'-------------------------------------

Vir_in = Ischarwaiting(#2)

If Vir_in = 1 Then

In_s1 = Waitkey(#2)

Print #1 , In_s1

End If

'------------------------------------

If In_s1 = "1" And Vir_in = 1 Then

Decr Sc

Goto Main1

End If

'---------------------------------------

If In_s1 = "2" And Vir_in = 1 Then

Incr Sc
Goto Main1

End If

Loop

Return

You might also like