Upload files to ''
Upload completed source code
This commit is contained in:
parent
5fcb911639
commit
92f5f2caa8
1
twoDigitCounter.bmk
Normal file
1
twoDigitCounter.bmk
Normal file
@ -0,0 +1 @@
|
|||||||
|
<BOOKMARKS/>
|
||||||
1
twoDigitCounter.brk
Normal file
1
twoDigitCounter.brk
Normal file
@ -0,0 +1 @@
|
|||||||
|
<BREAKS/>
|
||||||
100
twoDigitCounter.c
Normal file
100
twoDigitCounter.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* Digital Counter
|
||||||
|
* =-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
* This simple program is designed for the PIC18F45K22.
|
||||||
|
* It counts from zero to ninety-nine, displaying the count on two 7-segment modules.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Author: Marceline Kuo-Arrigo
|
||||||
|
* Created: 28.05.2019
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Declare counting variables and look up table
|
||||||
|
int ones=0;
|
||||||
|
int tens=0;
|
||||||
|
const int number_pattern[10] = {0x81,0xED,0x43,0x49,0x2D,0x11,0x10,0xCD,0x01,0x08};
|
||||||
|
|
||||||
|
/*
|
||||||
|
# display_number function
|
||||||
|
Accepts two parameters, first parameter is the number to be displayed.
|
||||||
|
Second parameter is which register to write to.
|
||||||
|
0 selects the segment on the left, the ones segment.
|
||||||
|
1 selects the segment on the right, the tens segment.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
display_number(9,0);
|
||||||
|
^ ^ Writes the number nine to the ones segment
|
||||||
|
*/
|
||||||
|
void display_number(int i, int r) {
|
||||||
|
LATD=number_pattern[i];
|
||||||
|
switch(r){
|
||||||
|
case 0:
|
||||||
|
LATC=0x02;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (LATD==number_pattern[0]) LATD=0xFF;
|
||||||
|
LATC=0x01;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LATC=0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialises timer0 interrupt for 250ms using values,
|
||||||
|
conveniently calculated by the timer calculator program,
|
||||||
|
available for free online from Mikroelektronika
|
||||||
|
https://www.mikroe.com/timer-calculator
|
||||||
|
*/
|
||||||
|
void InitTimer0(){
|
||||||
|
T0CON = 0x82;
|
||||||
|
TMR0H = 0x0B;
|
||||||
|
TMR0L = 0xDC;
|
||||||
|
GIE_bit = 1;
|
||||||
|
TMR0IE_bit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main code
|
||||||
|
void Interrupt(){
|
||||||
|
if (TMR0IF_bit){ // Only runs this section of code if the interrupt was timer0
|
||||||
|
|
||||||
|
TMR0IF_bit = 0; // Resets the timer0 flag bit
|
||||||
|
TMR0H = 0x0B;
|
||||||
|
TMR0L = 0xDC;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This section increments the ones counter unless if the ones counter has reached nine.
|
||||||
|
|
||||||
|
If it has, it resets the ones counter and increments the tens counter,
|
||||||
|
unless the tens counter is also nine.
|
||||||
|
If so, then it resets the tens counter instead.
|
||||||
|
*/
|
||||||
|
if(ones == 9){
|
||||||
|
ones=0;
|
||||||
|
|
||||||
|
if (tens==9) tens=0;
|
||||||
|
else if (tens!=9) tens++;
|
||||||
|
}
|
||||||
|
else if (ones != 9) ones++;
|
||||||
|
|
||||||
|
/* Write the tens and ones counter to the segments, whatever they may be*/
|
||||||
|
display_number(tens,1);
|
||||||
|
display_number(ones,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TRISC=0x00; //Sets Port C as outputs
|
||||||
|
TRISD=0x00; //Sets Port D as outputs
|
||||||
|
LATC=0x00; //Clears Port C to make sure it's 0.
|
||||||
|
|
||||||
|
/* Sets Port C & D to digital to make sure there's no unexpected behaviour. */
|
||||||
|
ANSELC=0;
|
||||||
|
ANSELD=0;
|
||||||
|
|
||||||
|
InitTimer0(); // Initialises timer0 interrupt
|
||||||
|
|
||||||
|
/* Loop forever doing nothing until interrupted */
|
||||||
|
for(;;){
|
||||||
|
}
|
||||||
|
}
|
||||||
42
twoDigitCounter.cfg
Normal file
42
twoDigitCounter.cfg
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<MCU_DEVICE_FLAGS>
|
||||||
|
<DEVICE>
|
||||||
|
<DEVICE_NAME>P18F45K22</DEVICE_NAME>
|
||||||
|
<VALUE>
|
||||||
|
<COUNT>11</COUNT>
|
||||||
|
<VALUE0>
|
||||||
|
<VAL>$300001:$0023</VAL>
|
||||||
|
</VALUE0>
|
||||||
|
<VALUE1>
|
||||||
|
<VAL>$300002:$001F</VAL>
|
||||||
|
</VALUE1>
|
||||||
|
<VALUE2>
|
||||||
|
<VAL>$300003:$003C</VAL>
|
||||||
|
</VALUE2>
|
||||||
|
<VALUE3>
|
||||||
|
<VAL>$300005:$00BF</VAL>
|
||||||
|
</VALUE3>
|
||||||
|
<VALUE4>
|
||||||
|
<VAL>$300006:$0081</VAL>
|
||||||
|
</VALUE4>
|
||||||
|
<VALUE5>
|
||||||
|
<VAL>$300008:$000F</VAL>
|
||||||
|
</VALUE5>
|
||||||
|
<VALUE6>
|
||||||
|
<VAL>$300009:$00C0</VAL>
|
||||||
|
</VALUE6>
|
||||||
|
<VALUE7>
|
||||||
|
<VAL>$30000A:$000F</VAL>
|
||||||
|
</VALUE7>
|
||||||
|
<VALUE8>
|
||||||
|
<VAL>$30000B:$00E0</VAL>
|
||||||
|
</VALUE8>
|
||||||
|
<VALUE9>
|
||||||
|
<VAL>$30000C:$000F</VAL>
|
||||||
|
</VALUE9>
|
||||||
|
<VALUE10>
|
||||||
|
<VAL>$30000D:$0040</VAL>
|
||||||
|
</VALUE10>
|
||||||
|
</VALUE>
|
||||||
|
</DEVICE>
|
||||||
|
</MCU_DEVICE_FLAGS>
|
||||||
116
twoDigitCounter.mcppi
Normal file
116
twoDigitCounter.mcppi
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
[DEVICE]
|
||||||
|
Name=P18F45K22
|
||||||
|
Clock=8000000
|
||||||
|
[MEMORY_MODEL]
|
||||||
|
Value=0
|
||||||
|
[BUILD_TYPE]
|
||||||
|
Value=0
|
||||||
|
[ACTIVE_TAB]
|
||||||
|
Value=twoDigitCounter.c
|
||||||
|
[USE_EEPROM]
|
||||||
|
Value=0
|
||||||
|
[USE_HEAP]
|
||||||
|
Value=0
|
||||||
|
[HEAP_SIZE]
|
||||||
|
Value=0
|
||||||
|
[EEPROM_DEFINITION]
|
||||||
|
Value=
|
||||||
|
[FILES]
|
||||||
|
Count=1
|
||||||
|
File0=twoDigitCounter.c
|
||||||
|
[BINARIES]
|
||||||
|
Count=0
|
||||||
|
[IMAGES]
|
||||||
|
Count=0
|
||||||
|
ActiveImageIndex=-1
|
||||||
|
[OPENED_FILES]
|
||||||
|
Count=0
|
||||||
|
[EEPROM]
|
||||||
|
Count=0
|
||||||
|
[ACTIVE_COMMENTS_FILES]
|
||||||
|
Count=0
|
||||||
|
[OTHER_FILES]
|
||||||
|
Count=0
|
||||||
|
[SEARCH_PATH]
|
||||||
|
Count=6
|
||||||
|
Path0=C:\Program Files (x86)\mikroC PRO for PIC\Defs\
|
||||||
|
Path1=C:\Program Files (x86)\mikroC PRO for PIC\uses\P18\
|
||||||
|
Path2=J:\Tafe\Term 2\Week 16\MicroFunds\Practical Assessment 2\src\
|
||||||
|
Path3=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT800\Uses\
|
||||||
|
Path4=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT810\Uses\
|
||||||
|
Path5=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT812\Uses\
|
||||||
|
[HEADER_PATH]
|
||||||
|
Count=3
|
||||||
|
Path0=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT800\Uses\
|
||||||
|
Path1=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT810\Uses\
|
||||||
|
Path2=C:\Program Files (x86)\mikroC PRO for PIC\Packages\FT812\Uses\
|
||||||
|
[HEADERS]
|
||||||
|
Count=0
|
||||||
|
[PLDS]
|
||||||
|
Count=0
|
||||||
|
[Useses]
|
||||||
|
Count=62
|
||||||
|
File0=ADC
|
||||||
|
File1=Button
|
||||||
|
File2=CAN_SPI
|
||||||
|
File3=Compact_Flash
|
||||||
|
File4=Compact_Flash_FAT16
|
||||||
|
File5=Conversions
|
||||||
|
File6=C_Math
|
||||||
|
File7=C_Stdlib
|
||||||
|
File8=C_String
|
||||||
|
File9=C_Type
|
||||||
|
File10=EEPROM
|
||||||
|
File11=EPSON_S1D13700
|
||||||
|
File12=FLASH
|
||||||
|
File13=Glcd
|
||||||
|
File14=Glcd_Fonts
|
||||||
|
File15=I2C
|
||||||
|
File16=Keypad4x4
|
||||||
|
File17=Lcd
|
||||||
|
File18=Lcd_Constants
|
||||||
|
File19=Manchester
|
||||||
|
File20=MemManager
|
||||||
|
File21=Mmc
|
||||||
|
File22=Mmc_FAT16
|
||||||
|
File23=Mmc_Fat16_Config
|
||||||
|
File24=One_Wire
|
||||||
|
File25=Port_Expander
|
||||||
|
File26=PrintOut
|
||||||
|
File27=PS2
|
||||||
|
File28=PWM12
|
||||||
|
File29=PWM3
|
||||||
|
File30=RS485
|
||||||
|
File31=Software_I2C
|
||||||
|
File32=Software_SPI
|
||||||
|
File33=Software_UART
|
||||||
|
File34=Sound
|
||||||
|
File35=SPI
|
||||||
|
File36=SPI_Ethernet
|
||||||
|
File37=SPI_Ethernet_24j600
|
||||||
|
File38=SPI_Glcd
|
||||||
|
File39=SPI_Lcd
|
||||||
|
File40=SPI_Lcd8
|
||||||
|
File41=SPI_T6963C
|
||||||
|
File42=Sprintf
|
||||||
|
File43=Sprinti
|
||||||
|
File44=Sprintl
|
||||||
|
File45=STMPE610
|
||||||
|
File46=T6963C
|
||||||
|
File47=TFT
|
||||||
|
File48=TFT_16bit
|
||||||
|
File49=TFT_16bit_Defs
|
||||||
|
File50=TFT_Defs
|
||||||
|
File51=TFT_TouchPanel
|
||||||
|
File52=Time
|
||||||
|
File53=TouchPanel
|
||||||
|
File54=Trigonometry
|
||||||
|
File55=UART
|
||||||
|
File56=FT800
|
||||||
|
File57=FT800_Defs
|
||||||
|
File58=FT810
|
||||||
|
File59=FT810_Defs
|
||||||
|
File60=FT812
|
||||||
|
File61=FT812_Defs
|
||||||
|
[EXPANDED_NODES]
|
||||||
|
Count=0
|
||||||
Loading…
Reference in New Issue
Block a user