Programming exercises. ABE221 Automation Section. Agenda. How to develop programs in PicBasic Write your code (BasicAtom’s editor) Compile your code (using PBP and MPASM) Program your code into 18F458 Microcontroller (using MElabs programmer) Demo Good coding practices Lab exercises
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
ABE221 Automation Section
Power(VDD = 5V)
Power (VDD = 5V)
How to use the 18F458
Port D 4-7 (DIO)
Port C 0-3 (DIO)
Port C 4-7 (DIO)
Port D 0,1 (DIO)
Port D 2,3 (DIO)
From Cetinkunt - Mechatronics
' Function Signal type Pin
' IR sensor left Analog input A0
' IR sensor right Analog input A1
' Middle servo PWM output C0
' Left servo PWM output C1
' Right servo PWM output C2
' RC channel 1 PWM input B7
' RC channel 2 PWM input B6
' Sonar echo pulse Digital In C4
' Sonar trigger pulse Digital out C5
' Serial out (LCD/terminal) Serial out C6
Define your clock (crystal)
Include library file allowing use of “N9600”, and “PORTC.6”
Set C-port data direction register (trisc)
Send ‘Hello World’ with carriage return continuously
Baud = #bits per second not bytes!
Measures pulse width on Pin. If State is zero, the width of a low pulse
is measured. If State is one, the width of a high pulse is measured.
The measured width is placed in Var. If the pulse edge never happens
or the width of the pulse is too great to measure, Var is set to zero. If
an 8-bit variable is used, only the LSB of the 16-bit measurement is
Pin is automatically made an input. Pin may be a constant, 0 - 15, or a
variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g.
Generates a pulse on Pin of specified Period. The pulse is generated by toggling the pin twice, thus the initial state of the pin determines the polarity of the pulse. Pin is automatically made an output. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
The resolution of PULSOUT is dependent upon the oscillator frequency.
If a 4MHz oscillator is used, the Period of the generated pulse will be in 10ms increments. If a 20MHz oscillator is used, Period will have a 2ms resolution. Defining an OSC value has no effect on PULSOUT. The resolution always changes with the actual oscillator speed.
‘ Send a pulse 1ms long (at 4MHz) to PORTB.5