From 92f5f2caa8cff8aa15ecab3dd83cdb1dfd911372 Mon Sep 17 00:00:00 2001 From: 9TailedCryptid Date: Tue, 28 May 2019 03:25:22 +0000 Subject: [PATCH] Upload files to '' Upload completed source code --- twoDigitCounter.bmk | 1 + twoDigitCounter.brk | 1 + twoDigitCounter.c | 100 ++++++++++++++++++++++++++++++++++++ twoDigitCounter.cfg | 42 +++++++++++++++ twoDigitCounter.mcppi | 116 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 260 insertions(+) create mode 100644 twoDigitCounter.bmk create mode 100644 twoDigitCounter.brk create mode 100644 twoDigitCounter.c create mode 100644 twoDigitCounter.cfg create mode 100644 twoDigitCounter.mcppi diff --git a/twoDigitCounter.bmk b/twoDigitCounter.bmk new file mode 100644 index 0000000..5179cc3 --- /dev/null +++ b/twoDigitCounter.bmk @@ -0,0 +1 @@ + diff --git a/twoDigitCounter.brk b/twoDigitCounter.brk new file mode 100644 index 0000000..7d476df --- /dev/null +++ b/twoDigitCounter.brk @@ -0,0 +1 @@ + diff --git a/twoDigitCounter.c b/twoDigitCounter.c new file mode 100644 index 0000000..3a43fc5 --- /dev/null +++ b/twoDigitCounter.c @@ -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(;;){ + } +} \ No newline at end of file diff --git a/twoDigitCounter.cfg b/twoDigitCounter.cfg new file mode 100644 index 0000000..6aa6d12 --- /dev/null +++ b/twoDigitCounter.cfg @@ -0,0 +1,42 @@ + + + + P18F45K22 + + 11 + + $300001:$0023 + + + $300002:$001F + + + $300003:$003C + + + $300005:$00BF + + + $300006:$0081 + + + $300008:$000F + + + $300009:$00C0 + + + $30000A:$000F + + + $30000B:$00E0 + + + $30000C:$000F + + + $30000D:$0040 + + + + diff --git a/twoDigitCounter.mcppi b/twoDigitCounter.mcppi new file mode 100644 index 0000000..11f85c9 --- /dev/null +++ b/twoDigitCounter.mcppi @@ -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