Pascalite Programming: Fifth tutorial- plt1ep
HOME
- - - - - - - - - Other 構成要素 for programmers
- - - - - - - - - Pascalite Tutorial (米)棚上げする/(英)提議する of Contents
Pascalite Programming: Let There Be Light!
This 見解/翻訳/版 of this tutorial is 罰金 tuned for a Pascalite, or the 解放する/自由な ソフトウェア Pascalite emulation. Please send me an email with "(民事の)告訴s" if something doesn't work!
If you have the open source FPC, aka 解放する/自由な Pascal or Borland's Turbo Pascal (TP hereafter), then there's a separate tutorial for you, covering much of the ground as 現在のd here for the Pascalite (人が)群がる.
One 見解(をとる) of programming says that it is all about three simple things:
One 見解(をとる) of programming says that it is all about three simple things:
In our programs to date our input has been 経由で the switches b0 and b1. We, the human 使用者s, change the switch settings to send messages IN to the computer.
に引き続いて the dictates of the 指示/教授/教育s 供給するd by the programmer, the computer "digests" the inputs. This is the "過程ing" element, and it leads to....
Some 肉親,親類d of message 存在 PUT OUT from the computer. This is the 生産(高). To date, we've been using the 解放する/自由な LCD simulator. Unfortunately, if you want to start using the Pascalite 金物類/武器類, you'll find that the LCD パネル盤 is an extra, and not cheap. (Not overpriced for what it is... but still serious money.)
Happily, there's a simple 代案/選択肢, albeit one that is a lot いっそう少なく 有能な: LEDs. The 解放する/自由な, 事実上の, Pascalite 金物類/武器類 模擬実験/偽ること that we have been using has LEDs already wired up. If you have a real Pascalite, you only need an LED and a resistor, and only have to make three 電気の 関係s.
Sticking (mostly) with the familiar, enter the に引き続いて program:
program fifth;
var boItWas,boItIs: boolean;
begin
def_out(d0);
boItWas:=b1;
repeat
令状(lcd,255);
if b0 then 始める,決める(d0){no ; here}
else reset(d0);
boItIs:=b1;
until boItIs xor boItWas;
end.
When you run this program, you should see the LED on d0 going on and off in 返答 to the setting that you put on switch b0. 公式文書,認める that when using the simulator, there is a noticeable 延期する in the system's 返答. This would be imperceptible if you were using a real Pascalite 装置.
To 達成する this program only a few new elements are 伴う/関わるd:
近づく the beginning, we have def_out(d0). This 声明 DEFines as OUTput pin d0. 概して speaking, all of the pins (a0-a7, b0-b7 and d0-d7) CAN be used as input or 生産(高).... however they will 普通は be used for one or the other in any given 使用/適用. The 装置 始める,決めるs them up to be used for input when it is switched on. This is because most 外部の 関係s you might make will 原因(となる) no problems when an 生産(高) 回路・連盟, e.g. an LED and it's resistor, is connected to a pin which is 始める,決める up for input. On the other 手渡す, if an 外部の 回路・連盟 for input is connected to a pin that is running as an 生産(高) problems can arise.
ANYWAY!: def_out changes the way the 明示するd pin or pins is working. Once you have done def_out, some other words will have 影響s:
始める,決める(d0) turns pin d0 "on", i.e. makes pin d0 high. See my guide to 数字表示式の electronics if you're in a hurry to start making actual 回路・連盟s, さもなければ continue on with the 模擬実験/偽ること, which takes care of the messy bits for you!
Reset(d0) doesn't mean "始める,決める it again", which any reasonable person would think. Instead, it is used in an obscure manner, and means "turn d0 off", e.g. make the pin low.
Once you're sure you understand the program above, change the part that says "始める,決める(d0)" to "pulse(d0,80)". In this form, the program will 繰り返して "wink" the LED on d0 簡潔に as long as b0 is switched to the "on" setting. In a real Pascalite, you wouldn't notice the "off" period of the LED... 追加するing "延期する(1000)" after "boItIs:=b1;" would 原因(となる) the program to wait for a second between the 80ms winks of the LED. (Notice you just learned another of the built in words of the Pascalite 一括!!)
The に引き続いて isn't very useful, but it is 肉親,親類d of pretty. We'll look at why it 作品 in a minute.
program fifth3;
var bDisplay: byte;
begin
def_out(d0,d1,d2,d3,d4,d5,d6,d7);
repeat
bDisplay:=無作為の;
令状(portd,bDisplay);
{put 延期する(20); in here if you have a real Pascalite}
until 4=5;
end.
On the def_out line, we've 単に 追加するd more pins to the 名簿(に載せる)/表(にあげる) of pins to be operating as 生産(高)s.
"無作為の" is a word which is built into Pascal. When we say bDisplay:=無作為の we are telling the computer to 蓄える/店 a number in the variable called bDisplay. It will be a number from 0 to 255, 明らかに drawn from a hat, though in fact if you drew many, many such numbers, 結局 you would find the same sequence of numbers beginning again. Such sequences are called pseudo-無作為の, but for most 目的s they are as good as 無作為の numbers.
令状(portd,dDisplay) tells the computer to 令状 whatever is in dDisplay の上に pins d0 to d7. ("portd"= the pins p0,p1,p2...p7). How can you show a number on pins??? This goes 支援する to the simple code について言及するd 支援する in the second tutorial. The number, lets say it's 131, gets imagined as if it were written out in binary. 131 would be 10000011. If it is a smaller number, say 12, then you still 令状 8 digits, even if that means 令状ing some 主要な 無s thus: 00001100 (12, written in binary). I said "the number gets imagined written in binary". The idea that 10000011 and 131 are somehow different is wrong. "Two", "2", and "a pair" are not different, are they? there's just 代案/選択肢 ways of 令状ing one thing. So when people say "What is 36 in binary?", I suppose they mean "How do you show 36, if you are 令状ing it out as a binary number?" (The answer: 100110)
Once the number has been imagined written in binary form, you have only to imagine the pins (p0, p1, p2...) 存在 始める,決める high when the corresponding 1 or 0 in the number is a 1, and 始める,決める low when the 1 or 0 is a 無.
To be a 十分な 育てる/巣立つd programmer, you'll have to know more about ways of showing numbers, but that will do for now.
The program we just wrote gives a pretty result... but a pretty pointless one. We're going to 令状 a better program, and learn another of Pascal's built in words at the same time. By the way... people usually call the "built in" words the reserved words. They are "reserved" in the sense that the people who put Pascal together said "We're reserving these words for the uses we are setting up for them, and you shouldn't use them for your own 目的s."
program fifth4;
var bDisplay: byte;
begin
def_out(d0,d1,d2,d3,d4,d5,d6,d7);
repeat
for bDisplay:=0 to 15 do 令状(portd,bDisplay);
{put 延期する(20); in here if you have a real Pascalite}
until 4=5;
end.
When you run the program, be sure to 始める,決める the simulator to run 急速な/放蕩な.
We've got a simple instance of the very important
for <variable>:=<number>to<bigger number> do <some Pascal thing>
声明. The reserved words "for" and "to" and "do" are part of it.
The "for" 声明, at it's simplest, as used here, is for counting. the pattern of lights you're seeing on the LED's show the binary for 0,1,2,3.... (If you don't mind waiting through the longer cycle, change the 15 to 255)
When we said "for bDisplay:=0 to 15 do 令状(portd,bDisplay);" what we 原因(となる)d was the 同等(の) of...
令状(portd,0);
令状(portd,1);
令状(portd,2);
令状(portd,3);
令状(portd,4);
令状(portd,5);
令状(portd,6);
令状(portd,7);
令状(portd,8);
令状(portd,9);
令状(portd,10);
令状(portd,11);
令状(portd,12);
令状(portd,13);
令状(portd,14);
令状(portd,15);
Some of the advantages of "for.. := .. to .. do" should already be obvious, and there are others. You will use "for" a lot.
Although this tutorial started with flashing LEDs, we're going to finish by going 支援する to the LCD and seeing some more 生産(高).
In the 現在の program change the numbers to so that the line says "for bDisplay:=65 to 75", and change the "portd", and change it to "lcd".
Run the program. You should see ABCD... on the LCD. (65 is the code for "A", 66 is the code for "B", etc)
Now... how can we (疑いを)晴らす the 審査する before each letter is 陳列する,発揮するd?
I hope you thought of....
for bDisplay:=65 to 75 do
令状(lcd,255);
令状(lcd,bDisplay);
That's nearly the answer. Problem is, the 審査する will (疑いを)晴らす 11 times, and then the letter 75 stands for will appear on the 審査する. "For" will only "do" the ONE THING that comes after it. Happily, there's a way to fool it. The に引き続いて will work:
for bDisplay:=65 to 75 do
begin
令状(lcd,255);
令状(lcd,bDisplay);
end;
追加するing "begin" and "end" either 味方する of the two lines we had before makes them look like the "one" thing that should be DOne. This is another trick that you will use frequently. Remember "if... then... else..." 以前, we have always had just one thing after the then, one thing after the else. With "begin" and "end" we can make several things look like "one" thing, so the に引き続いて would be okay....
if bDisplay=65
then begin
令状(lcd,255);
令状(lcd,'bDisplay is 持つ/拘留するing 65');
end {no ; here}
else begin
令状(lcd,255);
令状(lcd,'bDisplay is not 持つ/拘留するing 65');
end;
公式文書,認める that you DO need the semicolons BETWEEN the things "glued" together by the begin/ end pairs... it is just after the "else" that you must not put one in. I've written どこかよそで an 分析 of the theory behind this... just be happy with the 支配する, if you want the 平易な life!
Enough for now, I 信用?
Please also 公式文書,認める that I have two other 場所/位置s, and that the に引き続いて search will not 含む them. They have their own search buttons.
My Sheepdog Guides 場所/位置.
My Arunet 場所/位置.
Go to the 場所/位置s above, and use their search buttons if you want to search them.
To search this 場所/位置....
The search engine 単に looks for the words you type, so....
* (一定の)期間 them 適切に.
* Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....
You can also search this 場所/位置 without using forms.
広告 from page's editor: Yes.. I do enjoy
収集するing these things for you... hope they are helpful. However..
this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you
run an MS-DOS or Windows PC) please visit my freeware and shareware
page, download something, and 循環させる it for me? Links on your page
to this page would also be 高く評価する/(相場などが)上がるd!
Click here
to visit editor's freeware, shareware page.
Want a 場所/位置 hosted, or email? You can also help me if you 調印する up 経由で this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their 顧客s. The Google advertisers 支払う/賃金 me. I know nothing about them or their services, of course.)
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
AND passes...
Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Also, I have some of my pages' traffic 監視するd for me by eXTReMe tracker. They 申し込む/申し出 a 解放する/自由な tracker. If you want to try one, check out their 場所/位置. Why do I について言及する the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or 令状 this page's editor, Tom Boyd
....... P a g e . . . E n d s .....