Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 28.08.2008, 16:33   #1
Родион
Пользователь
 
Регистрация: 04.05.2008
Сообщений: 42
По умолчанию Перевод из Паскаля в Делфи

Есть листинг проги с коментами для паскаля
Но дельфи его не хавает, как я понимаю надо использовать какойто юнит
Помогите пожалуйста (ни когда с портами не работал)

Код:
PASCAL LANGUAGE FOR UART 8250 SYSTEMS
{
In the following pascal code 1-Wire I/O is accomplished using the serial port of an IBM PC or
compatible. The serial port must be capable of a 115,200 bps data rate.
}
Const
SPA : Word = 0; { Currently active serial port address }
Function TouchReset(N: Byte): Boolean;
{
This function transmits the 1-Wire protocol reset sequence to the device connected to COM port
number N. This sequence consists of a low pulse lasting a minimum of 480 us followed by a high
dead time lasting a minimum of 480 us. The function returns True if a presence detect pulse occurs
during the dead time, otherwise it returns False.
}
Const
Init : Array[1..4] of Boolean = (True, True, True, True);
Var
S : Array[1..4] of Word Absolute $40:0;
T : LongInt Absolute $40:$6C;
M : LongInt;
F : Boolean;
X, Y : Byte;
Begin
SPA := 0; TouchReset := False; { Assume failure }
If (N > 0) and (N < 5) and (S[N] > 0) then Begin { Legal port # }
SPA := S[N]; { Save active serial port address }
If Init[N] then Begin { Serial port requires initialization }
Port[SPA +3] := $83; { Set the DLAB }
Port[SPA] := 1; { Bit rate is }
Port[SPA +1] := 0; { 115200 bps }
Port[SPA +3] := 3; { 8 dta, 1 stp, no par }
Port[SPA +1] := 0; { No interrupts }
Port[SPA +4] := 3; { RTS and DTR on }
Init[N] := False; { Initialization completed }
End;
M := T +1; { Initialize the time limit }
Repeat until Port[SPA +5] and $60 = $60; { Await TBE & TSRE }
While Odd(Port[SPA +5]) do X := Port[SPA]; { Flush input }
Port[SPA +3] := $83; { Set DLAB }
port[SPA+1] := 0; { Baud rate is 10473 }
Port[SPA] := 11;
Port[SPA +3] := 3; { 8 data, 1 stop, no parity }
Port[SPA] := $F0; { Send the reset pulse }
Repeat { Wait until character back or timeout }
Y := Port[SPA +5];
F := Odd(Y);
until F or (T > M);
If F then X := Port[SPA] else X := $F0;
If (X <> $F0) Then Begin { If more bits back than sent }
TouchReset := True; { then there is a device }
If ((Y and $18) <> 0) Then Begin { Framing error or break }
Repeat until Port[SPA +5] and $60 = $60; { TBE & TSRE }
Repeat F := Odd(Port[SPA +5]) until F or (T > M);
If F then X := Port[SPA];
End;
End;
Port[SPA +3] := $83; { Set the DLAB }
Port[SPA] := 1; { Bit rate is 115200 bps }
Port[SPA +3] := 3; { 8 dta, 1 stp, no par }
End;
End;
Function TouchByte(X: Byte): Byte;
{
This function transmits the byte X to the device attached to the currently active serial port SPA, and
returns a byte from the device as its value.
}
Var
T : LongInt Absolute $40:$6C;
M : LongInt;
I, J : Byte;
Begin
If SPA = 0 then TouchByte := X else Begin
M := T +1; { Initialize the time limit }
Repeat until Port[SPA +5] and $60 = $60; { Await TBE & TSRE }
While Odd(Port[SPA +5]) do I := Port[SPA]; { Flush input }
I := 0; J := 0; { Initialize output & input bit counters }
Repeat
If Odd(Port[SPA +5]) then Begin
Inc(J); If Odd(Port[SPA]) then X := X or $80;
End else If (I<=J) and (Port[SPA+5] and $20 = $20) then Begin
If Odd(X) then Port[SPA] := $FF else Port[SPA] := 0;
X := X shr 1; Inc(I);
End;
Until (J = 8) or (T > M);
While (J < 8) do Begin
X := X shr 1 or $80;
Inc(J)
End;
TouchByte := X;
End;
End;
PASCAL LANGUAGE PULSEWIDTH FOR SYSTEMS USING 8253 AND 8250
Procedure PulWidth(X : Word);
{
This procedure creates a fixed pulse width for programming that is approximately independent of
system clock speed. When used in an IBM PC or compatible computer operating under MS-DOS, X
is in units of 0.419 microseconds for values of X greater than about 1000. The procedure can be used
with any processor having an 8250 UART I/O mapped to base port address SPA and an 8253 timer
mapped to base port address $40, operating with an input clock of 2.386363 MHz and with its count
limit set to the maximum value.
}
Var
M, N : Word;
Begin
Inline($FA); {Turn off interrupts}
Port[SPA +4] := Port[SPA +4] and $FD; {Apply Program Pulse on RTS}
Port[$43] := 0; {Freeze value in timer}
M := Port[$40] shl 8 or Port[$40]; {Read value in timer}
Repeat {Loop to consume real time}
Port[$43] := 0; {Freeze value in timer again}
N := Port[$40] shl 8 or Port[$40]; {Read new value in timer}
Until M - N >= X; {See if ”X” usec have elapsed}
Port[SPA +4] := Port[SPA +4] or 2; {Remove Program Voltage}
Inline($FB); {Turn interrupts on}
End;
Родион вне форума Ответить с цитированием
Старый 28.08.2008, 16:44   #2
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Цитата:
Но дельфи его не хавает
Ессно, а даже если ты и поправишь код под Делфи то придется выкинуть его ядро ибо в Делфи массива Port нет.
Этот код только в паскале можно провернуть. ито придется прописывать модули Dos и Crt
И закоментивать "PASCAL LANGUAGE PULSEWIDTH FOR SYSTEMS USING 8253 AND 8250"
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 28.08.2008, 16:52   #3
Родион
Пользователь
 
Регистрация: 04.05.2008
Сообщений: 42
По умолчанию

про точто закоментить это понятно
а насчет port чем его заменить можно
Родион вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Перевод с Паскаля на Дельфи!. HAMMAN Помощь студентам 10 18.01.2012 11:20
Как запустить в делфи программу паскаля? orange girl Помощь студентам 10 05.04.2011 08:50
Русификация паскаля Exact Паскаль, Turbo Pascal, PascalABC.NET 7 21.03.2008 14:15
Настройка паскаля Snake_ua Паскаль, Turbo Pascal, PascalABC.NET 7 18.10.2007 17:56
перенос с паскаля на си Ядовитый Общие вопросы C/C++ 2 29.06.2007 13:17