This will be 21 videos to show how to use Great Cow BASIC. I will try to make the 21 whilst I am required to mantain social distancing. I do hope to complete the 21 videos - only time will tell!
Enjoy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great Cow BASIC: Introduction to the 21 training sessions, the training themes and the resources
This video introduces the training session - watch this before you wade into the 21 sessions.
Follow me on YoutTube so I can make hot-links in the videos. Nowadays to make hot-links in the videos you need followers... and, I do not have enough followers to enable the hot-links.
This covered installing and using the tool chain to program an LED to flash.
The code used was as follows:
#CHIP16F18313' ----- Main body of program commences here.DoForever'Lighten LED onboard LED for 100 milliseconds:PulseOutRA1, 100ms'Then wait 900 milliseconds after LED goes off:Wait900msLoop
#CHIP16F18313DirRA1outDirRA2out'Set initial valueRA1=0RA2=1' ----- Main body of program commences here.DoForeverwait1sRA1=NOTRA1RA2=NOTRA1Loop
and
#CHIP16F18313DirRA1outDirRA2outDimLEDStateasByteLEDState=0' ----- Main body of program commences here.DoForeverIFLEDState=0thenRA1=1RA2=0LEDState=1elseRA1=0RA2=1LEDState=0endifwait100msLoop
The video
Last edit: Anobium 2020-03-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This covers setting the state of the two LEDs with an switch input switch.
So, far we have covered setup, outputs, creating a variable and now inputs.
The video shows a layout. Chris Roper provided this.. so, very grateful.
Code used was:
#CHIP16F18313
#OPTIONExplicit
#DEFINEGREENLEDRA1
#DEFINEREDLEDRA2
#DEFINESWITCHRA0DirGREENLEDoutDirREDLEDoutDirSWITCHin' ----- Main body of program commences here.DoForeverifSWITCH=OnthenGREENLED=OnREDLED=OffelseGREENLED=OffREDLED=OnendifLoop
and
#CHIP16F18313
#OPTIONExplicit
#DEFINEGREENLEDRA1
#DEFINEREDLEDRA2
#DEFINESWITCHRA0DirGREENLEDoutDirREDLEDoutDirSWITCHin' ----- Main body of program commences here.DoForeverSetWith(GREENLED, SWITCH)SetWith(REDLED, NOTSWITCH)Loop
The video
Last edit: Anobium 2020-03-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I saw this on email and commented on use of setwith. It seemed a jump as it's a command I have never used. I have used set. I looked setwith up in gcb help and it looked complicated.
The demo was fine until then. This is just feed back not criticism. It just seemed a big jump for a beginner.
I hate making videos cos I don't have the cameras,mics or even know how to use free video software like proper screen capture...using spare time to learn but some is easier than other.
Stay well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It was a good video. Not for avr users really. OK I use the uno port names ie port c,1 but there's the 328 include that converts digital 10 whatever to the ports and that is used in gcb demos...I prefer ports and define them as in the video so that was safe and option explicit too.
avr would be just plug an usb lead in and that is it. Plus you get to use the gcb terminal to show results without extra hardware
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
AVR is relatively static in terms of the development program. The essentials of the chips are very similar hence less changes to Great Cow BASIC to support AVR.
PIC is relatively hectice in terms of the development program. The essentials of the chips are very different hence all the changes to Great Cow BASIC to support the newer PICs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This covers using the ADC to read the state of a potentiometer to set the state of the four LEDs.
So, far we have covered setup, outputs, creating a variable, inputs and now ADC.
The video shows the latest layout. Chris Roper provided this.. so, very grateful. We will be using this layout for remainder of the training.
Code used was:
#chip16f18313
#optionExplicit
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin'Declare or dimensiona a Byte variable to store the ADC valueDimADCValueasByte' ----- Main body of program commences here.DoForever'ReadAD return a byte value of 0 to 255ADCValue=ReadAD(ANA0)'Test to see if in the mid pointifADCValue<128thenLED1=0LED2=0LED3=1LED4=1elseLED1=1LED2=1LED3=0LED4=0endifLoop
The video
Last edit: Chris Roper 2020-03-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For those wishing to build the 21-Trainer board used in this and subsequent videos in this series here are a couple of construction and usage tips.
The Two wires (Yellow and Red) show on top of the TrimPot (Potentiometer) are actually beneath the POT. They are depicted as they are for clarity when building the board to show which rows/columns they are in.
The Blue and Black wires near the ICSP connector overlap by one column, they are not connected to each other.
The two Green LEDs have the Anode (positive or input) Pin Bent and extended out, they are not wired in parallel with the RED LEDs just positioned as such for visual layout.
All 4 LEDs share a common Ground (Vss or V0) connection. It is provided by the Long Black wire from the Vss Pin of the device, and it bridges between the upper and lower board sections via the Push Button Switch.
Here is an image of a constructed board:
The Board and the exercises are designed around the PIC16F18313 chip shown in the drawing but any 8 pin PIC will work in this circuit. Not all of the exercises will work on an older PIC but many will so play along even if you do not have a PIC16F18313 device.
You can also Build a Board to accept a 14 PIN PIC by using a slim Push Button switch or mounting your switch off the Breadboard:
This option may be useful if you do not have any 8 pin PIC Devices, as again most examples will work on the 14 pin device.
If you have a Microchip Low Pin Count Demo Board from either the PICkit2 or PICKit3 bundle you can of course use that or the later Curiosity Board.
If you do not have any suitable PIC devices then you may use an Arduino Board instead and if you do not have an Arduino to try it on you can use an Arduino Simulator:
So lets turn The 21 Days of Lockdown into 21 days to Lockdown your Great Cow BASIC skills.
We will have things of interest for users of all levels and you have no excuse not to follow along.
If you don't have any hardware you can use the Simulator instead, and we all have time on our hands at the moment.
Cheers, and stay safe in these worrying times,
Chris Roper
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This covers using PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:
Software PWM. This method can be used on any chip, but, the signal is only operational when the command is operational.
Hardware PWM using the CCP/PMW module. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
#chip16F18313
#optionExplicit
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin; ----- Constants'PWM constant. This is a required constant.
#definePWM_Out1LED1; ----- Define Hardware settings'PWM port out. This is not required but good practice.dirPWM_Out1out'A potentiometer is attached to ANO; ----- Variables' No Variables specified in this example.; ----- Main body of program commences here.do'100 cycles is a purely arbitrary valuePWMOut1, ReadAD(AN0), 100wait5sloopend
and
#chip16F18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: CCP1RA1PPS=0x000C'CCP1 > RA1CCP1PPS=0x0001'RA1 > CCP1 (bi-directional)RA2PPS=0x000C'CCP1 > RA2CCP1PPS=0x0002'RA2 > CCP1 (bi-directional)RA4PPS=0x000C'CCP1 > RA3CCP1PPS=0x0004'RA3 > CCP1 (bi-directional)RA5PPS=0x000C'CCP1 > RA5CCP1PPS=0x0005'RA5 > CCP1 (bi-directional)EndSub'Template comment at the end of the config file
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin
#definePWM_Freq40'Frequency of PWM in KHz
#definePWM_Duty60'Duty cycle of PWM (%)DoforeverPWMOnwait2sPWMOffwait2sLoop
The video
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evan, I have sent a link to this to several of my cohorts. Great Job, I can't wait to see the rest. Social distancing is getting stricter here in Florida and has given me the opportunity to get back in to the Great Cow Basic Groove. Good Stuff!!!!
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#chip16f18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: PWM5RA1PPS=0x0002'PWM5 > RA1RA2PPS=0x0002'PWM5 > RA2RA4PPS=0x0002'PWM5 > RA4RA5PPS=0x0002'PWM5 > RA5EndSub'Template comment at the end of the config file
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin'Declare or dimensiona a Byte variable to store the ADC valueDimADCValueasByte' ----- Main body of program commences here.HPWM5, 40, ADCValue, 2DoForever'ReadAD return a byte value of 0 to 255ADCValue=ReadAD(ANA0)HPWMUpdate5, ADCValuewait100msLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great Cow BASIC: Part 6: Controlling the outputs to set power of LEDs with PWM/CCPn & PWMn Module - this allows you to nine PWM signals with very small program memory usage.
The training session explains how to set up and use multiple channels for 1) CCP/PWM and 2) the PWM module with a static PWM frequency and duty
This training session uses PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:
CCP/PWM channel. This method support up to nine CCP/PWM channels. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.
PWM module. This method support up to nine PWM modules. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
#chip16F18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: CCP1RA1PPS=0x000C'CCP1 > RA1CCP1PPS=0x0001'RA1 > CCP1 (bi-directional)'Module: CCP2RA2PPS=0x000D'CCP2 > RA2CCP2PPS=0x0002'RA2 > CCP2 (bi-directional)EndSub'Template comment at the end of the config file
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin
#definePWM_Timer2_Freq16
#definePWM_1_Duty75
#definePWM_1_Clock_Source2
#definePWM_2_Duty25
#definePWM_2_Clock_Source2PWMOn(1)PWMOn(2)doloop
and
#chip16F18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: PWM5RA1PPS=0x0002'PWM5 > RA1'Module: PWM6RA2PPS=0x0003'PWM6 > RA2EndSub'Template comment at the end of the config file
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin
#definePWM_Timer2_Freq16
#definePWM_5_Duty75
#definePWM_5_Clock_Source2
#definePWM_6_Duty25
#definePWM_6_Clock_Source2PWMOn(1, PWMModule)PWMOn(2, PWMModule)doloop
Great Cow BASIC: Part 7: Controlling the outputs to set duty and frequencies of LEDs with PWM Module.
The training session explains how to set up and use multiple PWM modules PWM module with a variable PWM duty and frequency.
This training session uses PWM to the power to some of the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:
PWM module. This method support up to nine PWM modules. The signal is constant and uses no CPU cycles. The method shown generates a variable duty cycle and frequency. These frequency is changed within the program using a simple calculation and the duty cycle is changed using the value returned from the 10bit ADC. The chip requires the use of PPS - this is also covered.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
'Static demo at start'''A demonstration program for GCGB and GCB.'''The program shows PWM options for this device''':'''This demonstration how use the PWM 10 bit Module but with this method you can change the parameters.''':'''Change the PPS to test different module, but, remember to change the CONSTANTS!!'''This default to PWM but you can change the PWM parameters.''''''You can make the ASM smaller, adapt the PWM Optimisation!!''''''@author EvanV'''@licence GPL'''@version 1.0a'''@date 24.03.2020'''*************************************************************************'Chip Settings
#CHIP16F18313'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: PWM5RA1PPS=0x0002'PWM5 > RA1'Module: PWM6RA2PPS=0x0003'PWM6 > RA2EndSub'Template comment at the end of the config fileDirRA1OutDirRA2OutDo'use for-loop to show the duty changing a 10bit valueDimdutyvalueAsWordFordutyvalue=0To1023HPWM5, 8, dutyvalue, 2HPWM6, 8, 1023-dutyvalue, 2wait5msNextLoop
and the code created during the video is:
#chip16f18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: PWM5RA1PPS=0x0002'PWM5 > RA1'Module: PWM6RA2PPS=0x0003'PWM6 > RA2EndSub'Template comment at the end of the config file
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHinDimADCValueaswordDimDynamicFrqasByteDynamicFrq=1DoforeverADCValue=ReadAD10(ANA0)HPWM(5, DynamicFrq, ADCValue, 2)HPWM(6, DynamicFrq, 1023-ADCValue, 2)wait100msDynamicFrq=DynamicFrq+1ifDynamicFrq>32thenDynamicFrq=1endifLoop''' GCB Optimisation file'Optmise PWM.h
#defineUSE_HPWMCCP1FALSE
#defineUSE_HPWMCCP2FALSE
#defineUSE_HPWMCCP3FALSE
#defineUSE_HPWMCCP4FALSE
#defineUSE_HPWMCCP5FALSE
#defineUSE_HPWM1FALSE
#defineUSE_HPWM2FALSE
#defineUSE_HPWM3FALSE
#defineUSE_HPWM4FALSE
#defineUSE_HPWM5TRUE
#defineUSE_HPWM6TRUE
#defineUSE_HPWM7FALSE
#defineUSE_HPWM8FALSE
#defineUSE_HPWM_TIMER2TRUE
#defineUSE_HPWM_TIMER4FALSE
#defineUSE_HPWM_TIMER6FALSE'Optimise A-d.h'Standard family chips
#defineUSE_AD0TRUE
#defineUSE_AD1FALSE
#defineUSE_AD2FALSE
#defineUSE_AD2FALSE
#defineUSE_AD3FALSE
#defineUSE_AD4FALSE
#defineUSE_AD5FALSE
#defineUSE_AD6FALSE
#defineUSE_AD7FALSE
#defineUSE_AD8FALSE
#defineUSE_AD9FALSE
#defineUSE_AD10FALSE
#defineUSE_AD11FALSE
#defineUSE_AD12FALSE
#defineUSE_AD13FALSE
#defineUSE_AD14FALSE
#defineUSE_AD15FALSE
#defineUSE_AD16FALSE
#defineUSE_AD17FALSE
#defineUSE_AD18FALSE
#defineUSE_AD19FALSE
#defineUSE_AD20FALSE
#defineUSE_AD21FALSE
#defineUSE_AD22FALSE
#defineUSE_AD23FALSE
#defineUSE_AD24FALSE
#defineUSE_AD25FALSE
#defineUSE_AD26FALSE
#defineUSE_AD27FALSE
#defineUSE_AD28FALSE
#defineUSE_AD29FALSE
#defineUSE_AD30FALSE
#defineUSE_AD31FALSE
#defineUSE_AD32FALSE
#defineUSE_AD33FALSE
#defineUSE_AD34FALSE'Family of chips based on 16f1688x with ADCON3 register
#defineUSE_ADA0FALSE
#defineUSE_ADA1FALSE
#defineUSE_ADA2FALSE
#defineUSE_ADA3FALSE
#defineUSE_ADA4FALSE
#defineUSE_ADA5FALSE
#defineUSE_ADA6FALSE
#defineUSE_ADA7FALSE
#defineUSE_ADB0FALSE
#defineUSE_ADB1FALSE
#defineUSE_ADB2FALSE
#defineUSE_ADB3FALSE
#defineUSE_ADB4FALSE
#defineUSE_ADB5FALSE
#defineUSE_ADB6FALSE
#defineUSE_ADB7FALSE
#defineUSE_ADC0FALSE
#defineUSE_ADC1FALSE
#defineUSE_ADC2FALSE
#defineUSE_ADC3FALSE
#defineUSE_ADC4FALSE
#defineUSE_ADC5FALSE
#defineUSE_ADC6FALSE
#defineUSE_ADC7FALSE
#defineUSE_ADD0FALSE
#defineUSE_ADD1FALSE
#defineUSE_ADD2FALSE
#defineUSE_ADD3FALSE
#defineUSE_ADD4FALSE
#defineUSE_ADD5FALSE
#defineUSE_ADD6FALSE
#defineUSE_ADD7FALSE
#defineUSE_ADE0FALSE
#defineUSE_ADE1FALSE
#defineUSE_ADE2FALSE
Great Cow BASIC: Part 8: Controlling the outputs to set the LEDs using a state engine
The training session explains how to use SELECT CASE to create a simple state machine that controls the LEDs.
This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:
How to create a simple state machine controlled by a switch.
How to create a simple state machine controlled by the value of the ADC.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
#chip16F18313
#optionExplicit
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin/*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---Type: -------|LED|LED|SW |LED|LED|ADCReal: RA5 RA4 RA3 RA2 RA1Name: -------| 4 | 3 |SW | 2 | 1 |ANA0-----------------------------------------*//*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---CAP: -------|LED|LED|SW |LED|LED|ADC|------------------------------------------STATE TABLESTATE 1 | 0 | 0 | | 0 | 1 | |STATE 2 | 0 | 0 | | 1 | 0 | |STATE 3 | 0 | 1 | | 0 | 0 | |STATE 5 | 1 | 0 | | 0 | 0 | |*/DimLEDStateasByte'Initilize the variable to zeroLEDState=0' ----- Main body of program commences here.DoForeverSelectCaseLEDStatecase0'Set one LED on... could 1 or ONLED1=1LED2=0LED3=0LED4=0LEDState=1case1LED1=0LED2=1LED3=0LED4=0LEDState=2case2LED1=0LED2=0LED3=1LED4=0LEDState=3case3LED1=0LED2=0LED3=0LED4=1LEDState=0endselectwait500mswaitwhileswitch=0Loop
Great Cow BASIC: Part 9: Controlling the LEDs rotation direction using a switch and an Interrupt.
The training session explains how to use a switch and an interrupt routine set the state machine that controls the LEDs.
This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs, PWM and now interrupts.
The session shows:
1. Adapting the training session 8a code to create a simple state machine controlled by a switch.
2. Adding an interrupt to handle the switch press event which then changes the simple state machine.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
#chip16F18313
#optionExplicit
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin/*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---Type: -------|LED|LED|SW |LED|LED|ADCReal: RA5 RA4 RA3 RA2 RA1Name: -------| 4 | 3 |SW | 2 | 1 |ANA0-----------------------------------------*//*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---CAP: -------|LED|LED|SW |LED|LED|ADC|------------------------------------------STATE TABLESTATE 1 | 0 | 0 | | 0 | 1 | |STATE 2 | 0 | 0 | | 1 | 0 | |STATE 3 | 0 | 1 | | 0 | 0 | |STATE 5 | 1 | 0 | | 0 | 0 | |*/DimLEDStateasInteger'Initilize the variable to zeroLEDState=0DimDirectionasIntegerDirection=-1' ----- Main body of program commences here.DoForeverSelectCaseLEDStatecase0'Set one LED on... could 1 or ONLED1=1LED2=0LED3=0LED4=0case1LED1=0LED2=1LED3=0LED4=0case2LED1=0LED2=0LED3=1LED4=0case3LED1=0LED2=0LED3=0LED4=1endselectLEDState=LEDState+DirectionIfLEDState=4thenLEDState=0IfLEDState=-1thenLEDState=3wait500msifswitch=0thenifDirection=1thenDirection=-1elseDirection=1Endifwaitwhileswitch=0endifLoop
and the code created during the video is:
#chip16F18313
#optionExplicit
#defineLED1RA1
#defineLED2RA2
#defineLED3RA4
#defineLED4RA5
#defineSWITCHRA3
#defineVR1RA0DirLED1outDirLED2outDirLED3outDirLED4outDirSWITCHin/*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---Type: -------|LED|LED|SW |LED|LED|ADCReal: RA5 RA4 RA3 RA2 RA1Name: -------| 4 | 3 |SW | 2 | 1 |ANA0-----------------------------------------*//*-------------------LATA-----------------Bit#: -7---6---5---4---3---2---1---0---CAP: -------|LED|LED|SW |LED|LED|ADC|------------------------------------------STATE TABLESTATE 1 | 0 | 0 | | 0 | 1 | |STATE 2 | 0 | 0 | | 1 | 0 | |STATE 3 | 0 | 1 | | 0 | 0 | |STATE 5 | 1 | 0 | | 0 | 0 | |*/OnInterruptPORTChangecallMyISRIOCAN3=1DimLEDStateasInteger'Initilize the variable to zeroLEDState=0DimDirectionasIntegerDirection=-1' ----- Main body of program commences here.DoForeverSelectCaseLEDStatecase0'Set one LED on... could 1 or ONLED1=1LED2=0LED3=0LED4=0case1LED1=0LED2=1LED3=0LED4=0case2LED1=0LED2=0LED3=1LED4=0case3LED1=0LED2=0LED3=0LED4=1endselectLEDState=LEDState+DirectionIfLEDState=4thenLEDState=0IfLEDState=-1thenLEDState=3waitReadAD10(ANA0)msLoopSubMyISRifDirection=1thenDirection=-1elseDirection=1EndifIOCAF3=0EndSub
Great Cow BASIC: Part 10: Using the software to communicate via the serial port to a PC terminal.
The video shows using the software to communicate via the serial connection to a PC terminal, and, show the value of the potentiate
The session shows:
1. Connecting the USART module to RA5 using PPS, and, send ‘Hello World’
2. Adapting the program to send the value of ADC on the terminal
3. Adapting the program to send a ‘scaled’ value of ADC on the terminal
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
#chip16f18313
#optionExplicit'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: EUSARTRA5PPS=0x0014'TX > RA5EndSub'Template comment at the end of the config file'USART settings for USART1
#defineUSART_BAUD_RATE9600
#defineUSART_TX_BLOCKING
#defineUSART_DELAYOFF/*Part One - Hello World do Forever HSerPrint "Hello World" HSerPrintCRLF wait 1 s loop*//*Part Two - Send the ADC value to the terminal software do Forever HSerPrint "ReadAD = " HSerPrint ReadAD( ANA0 ) HSerPrintCRLF wait 1 s loop*///Partthree-Sendascaled, withascaledvalueofbetween0and100whentheinputvalueis0to236, ADCvaluetotheterminalsoftwaredoForeverHSerPrint"Scaled = "HSerPrintScale(ReadAD(ANA0), 0, 236, 0, 100)HSerPrintCRLFwait1sloop
Great Cow BASIC: Part 11: Using the software to create bi-directional communications between the microcontroller and the PC terminal software using an interrupt driven serial ring buffer.
This session shows using the software to communicate between the PC terminal software and the microcontroller - what you send to the microcontroller is returned back. From this example you can build 100s of solutions.
The session shows:
1. We will connect the USART module using PPSTool
RA5 for TX
RA2 for RX
2. We use existing code in the Help to create overall program
3. Send data... And the data comes back
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
~~~
chip 16f18313
option Explicit
'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.6.1'PinManager data: v1.79.0'Generated for 16f18313''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18313SubInitPPS'Module: EUSARTRA5PPS=0x0014'TX > RA5RXPPS=0x0002'RA2 > RXEndSub'Template comment at the end of the config file' Add PPS if appropiate for your chip' [change to your config] This is the config for a serial terminal' turn on the RS232 and terminal port.' Define the USART settings
#DEFINEUSART_BAUD_RATE9600'This assumes you are using an ANSI compatible terminal. Use PUTTY.EXE it is very easy to use.' Main program'Create the supporting variablesDimnext_inAsByteDimnext_outAsByteDimsyncbyteAsByteDimtemppntAsByte' Constants etc required for Buffer Ring
#DEFINEBUFFER_SIZE8
#DEFINEbkbhit(next_in<>next_out)'Define the BufferDimbuffer(BUFFER_SIZE-1)'we will use element 0 in the array as part of out buffer'Call init the bufferInitBufferRingHSerSend10HSerSend13HSerSend10HSerSend13HSerPrint"Started: Serial between two devices"HSerSend10HSerSend13'Get character(s) and send backDo' Do we have data in the buffer?ifbkbhitthen'Send the next character in the buffer, exposed via the function `bgetc` back the terminalHSerSendbgetcendifLoop'Supporting subroutinesSubreadUSARTbuffer(next_in)=HSerReceivetemppnt=next_innext_in=(next_in+1)%BUFFER_SIZEIf(next_in=next_out)Then' buffer is full!!next_in=temppntEndIfEndSubFunctionbgetcDimlocal_next_outasByte'maintain a local copy of the next_out variable to ensure it does not change when an Interrupt happenslocal_next_out=next_outbgetc=buffer(local_next_out)local_next_out=(local_next_out+1)%BUFFER_SIZEINTOFFnext_out=local_next_outINTONEndFunctionSubInitBufferRing'Set the buffer to the first addressnext_in=0next_out=0'Interrupt Handler - some have RCIE and some have U1RXIE, so handle
#IFDEFBIT(RCIE)OnInterruptUsartRX1ReadyCallreadUSART
#ENDIF
#IFDEFBIT(U1RXIE)OnInterruptUART1ReceiveInterruptCallreadUSART
#ENDIFEndSub~~~
See https://www.youtube.com/playlist?list=PLN9gcw34mhurcKllCY1ArcuX0F4Zdcmkh
This will be 21 videos to show how to use Great Cow BASIC. I will try to make the 21 whilst I am required to mantain social distancing. I do hope to complete the 21 videos - only time will tell!
Enjoy
Great Cow BASIC: Introduction to the 21 training sessions, the training themes and the resources
This video introduces the training session - watch this before you wade into the 21 sessions.
Follow me on YoutTube so I can make hot-links in the videos. Nowadays to make hot-links in the videos you need followers... and, I do not have enough followers to enable the hot-links.
Resources:
The presentation used in this video can be found here:
See https://1drv.ms/p/s!Ase-PX_n_4cvg4ETos-tLcB8j6Kxnw?e=VQd1AF
Source code:
They are in Github and your Great Cow BASIC installation. See https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/Training_Support/PIC16F18313
Videos:
They are in YouTube, see See https://www.youtube.com/playlist?list=PLN9gcw34mhurcKllCY1ArcuX0F4Zdcmkh
Presentations:
They are in a OneDrive folder, see See https://1drv.ms/u/s!Ase-PX_n_4cvg4B6WZWC2tQtDjF3pg?e=CELgnq
Great Cow BASIC tool chain spreadsheet:
In OneDrive, see https://1drv.ms/x/s!Ase-PX_n_4cvg4B2oCXJ9FuSm19Urg?e=zQbngZ
PIC timer calculator:
In OneDrive, see https://1drv.ms/x/s!Ase-PX_n_4cvg4Bnzhfm0K0_GD0Msg?e=2w0xED
The video can be found here:
https://youtu.be/HpHDKLPF8Wc
Last edit: Anobium 2020-04-15
Training Video #1
This covered installing and using the tool chain to program an LED to flash.
The code used was as follows:
The video https://youtu.be/HpHDKLPF8Wc
Last edit: Anobium 2020-04-15
Training Video #2
This covers flashing two LEDs alternatively.
Code used was
and
The video
Last edit: Anobium 2020-03-25
Training Video #3
This covers setting the state of the two LEDs with an switch input switch.
So, far we have covered setup, outputs, creating a variable and now inputs.
The video shows a layout. Chris Roper provided this.. so, very grateful.
Code used was:
and
The video
Last edit: Anobium 2020-03-26
Nice! For German not native English Listener it is easy to follow! Very good.
Thank you for the feeback!
someone could dub it to German. Es sind nur Worte
I saw this on email and commented on use of setwith. It seemed a jump as it's a command I have never used. I have used set. I looked setwith up in gcb help and it looked complicated.
The demo was fine until then. This is just feed back not criticism. It just seemed a big jump for a beginner.
I hate making videos cos I don't have the cameras,mics or even know how to use free video software like proper screen capture...using spare time to learn but some is easier than other.
Stay well.
Re SetWith(). It is an option. To show different approaches. The reality is that there are many ways to set the state and the training only shows two.
It was a good video. Not for avr users really. OK I use the uno port names ie port c,1 but there's the 328 include that converts digital 10 whatever to the ports and that is used in gcb demos...I prefer ports and define them as in the video so that was safe and option explicit too.
avr would be just plug an usb lead in and that is it. Plus you get to use the gcb terminal to show results without extra hardware
The video clearly states this is for PIC. We should do same training for AVR - may be a book where we can have PIC and AVR sections.
If we took a survey, avr vs pic users? Please vote. Do you use pic or a uno/nano thingy?
Dunno answer to usage.
AVR is relatively static in terms of the development program. The essentials of the chips are very similar hence less changes to Great Cow BASIC to support AVR.
PIC is relatively hectice in terms of the development program. The essentials of the chips are very different hence all the changes to Great Cow BASIC to support the newer PICs.
Training Video #4
This covers using the ADC to read the state of a potentiometer to set the state of the four LEDs.
So, far we have covered setup, outputs, creating a variable, inputs and now ADC.
The video shows the latest layout. Chris Roper provided this.. so, very grateful. We will be using this layout for remainder of the training.
Code used was:
The video
Last edit: Chris Roper 2020-03-27
For those wishing to build the 21-Trainer board used in this and subsequent videos in this series here are a couple of construction and usage tips.
The Two wires (Yellow and Red) show on top of the TrimPot (Potentiometer) are actually beneath the POT. They are depicted as they are for clarity when building the board to show which rows/columns they are in.
The Blue and Black wires near the ICSP connector overlap by one column, they are not connected to each other.
The two Green LEDs have the Anode (positive or input) Pin Bent and extended out, they are not wired in parallel with the RED LEDs just positioned as such for visual layout.
All 4 LEDs share a common Ground (Vss or V0) connection. It is provided by the Long Black wire from the Vss Pin of the device, and it bridges between the upper and lower board sections via the Push Button Switch.
Here is an image of a constructed board:
The Board and the exercises are designed around the PIC16F18313 chip shown in the drawing but any 8 pin PIC will work in this circuit. Not all of the exercises will work on an older PIC but many will so play along even if you do not have a PIC16F18313 device.
You can also Build a Board to accept a 14 PIN PIC by using a slim Push Button switch or mounting your switch off the Breadboard:
This option may be useful if you do not have any 8 pin PIC Devices, as again most examples will work on the 14 pin device.
If you have a Microchip Low Pin Count Demo Board from either the PICkit2 or PICKit3 bundle you can of course use that or the later Curiosity Board.
If you do not have any suitable PIC devices then you may use an Arduino Board instead and if you do not have an Arduino to try it on you can use an Arduino Simulator:
The simulator may be downloaded from here:
https://sourceforge.net/projects/picsim/
And the Workspace File from here:
https://sourceforge.net/p/gcbasic/discussion/579127/thread/6a952bedb2/05aa/attachment/Arduino-21-Lockdown.pzw
So lets turn The 21 Days of Lockdown into 21 days to Lockdown your Great Cow BASIC skills.
We will have things of interest for users of all levels and you have no excuse not to follow along.
If you don't have any hardware you can use the Simulator instead, and we all have time on our hands at the moment.
Cheers, and stay safe in these worrying times,
Chris Roper
Training Video #5
This covers using PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
and
The video
Evan, I have sent a link to this to several of my cohorts. Great Job, I can't wait to see the rest. Social distancing is getting stricter here in Florida and has given me the opportunity to get back in to the Great Cow Basic Groove. Good Stuff!!!!
PMW Training - damn cool
Great Cow BASIC: Part 6: Controlling the outputs to set power of LEDs with PWM/CCPn & PWMn Module - this allows you to nine PWM signals with very small program memory usage.
The training session explains how to set up and use multiple channels for 1) CCP/PWM and 2) the PWM module with a static PWM frequency and duty
This training session uses PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:
CCP/PWM channel. This method support up to nine CCP/PWM channels. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.
PWM module. This method support up to nine PWM modules. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
and
The video is here: https://youtu.be/532gxSRI_w8
Great Cow BASIC: Part 7: Controlling the outputs to set duty and frequencies of LEDs with PWM Module.
The training session explains how to set up and use multiple PWM modules PWM module with a variable PWM duty and frequency.
This training session uses PWM to the power to some of the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
and the code created during the video is:
The video is here: https://youtu.be/3Eo7W7k3yqA
Great Cow BASIC: Part 8: Controlling the outputs to set the LEDs using a state engine
The training session explains how to use SELECT CASE to create a simple state machine that controls the LEDs.
This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
and the code created during the video is:
The video is here: https://youtu.be/ASLWNJemIJ8
Great Cow BASIC: Part 9: Controlling the LEDs rotation direction using a switch and an Interrupt.
The training session explains how to use a switch and an interrupt routine set the state machine that controls the LEDs.
This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs, PWM and now interrupts.
The session shows:
1. Adapting the training session 8a code to create a simple state machine controlled by a switch.
2. Adding an interrupt to handle the switch press event which then changes the simple state machine.
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
and the code created during the video is:
The video is here: https://youtu.be/6nvX3ceWY8Q
Great Cow BASIC: Part 10: Using the software to communicate via the serial port to a PC terminal.
The video shows using the software to communicate via the serial connection to a PC terminal, and, show the value of the potentiate
The session shows:
1. Connecting the USART module to RA5 using PPS, and, send ‘Hello World’
2. Adapting the program to send the value of ADC on the terminal
3. Adapting the program to send a ‘scaled’ value of ADC on the terminal
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
The video is here: https://youtu.be/hm33YCXMBfY
Great Cow BASIC: Part 11: Using the software to create bi-directional communications between the microcontroller and the PC terminal software using an interrupt driven serial ring buffer.
This session shows using the software to communicate between the PC terminal software and the microcontroller - what you send to the microcontroller is returned back. From this example you can build 100s of solutions.
The session shows:
1. We will connect the USART module using PPSTool
RA5 for TX
RA2 for RX
2. We use existing code in the Help to create overall program
3. Send data... And the data comes back
The video uses the latest board layout, same as training session 4, from Chris Roper provided this.
Code used was:
~~~
chip 16f18313
option Explicit
The video is here: https://youtu.be/dyMyRMwemDY