Hello everyone, there is a portion of code that I want to repeat 32 times and then stop until the input goes to low again. Instead of copying and pasting the code 32 times as shown below, I am sure that there is a way to tell the micro controller to run the code 32 times. I am using the PIC18F452. Copying a pasting a code over and over gets too long to the point that if i need to repeat a code 100 times, i will run out of memory. The software I am using is microC pro v.7.1.0.
Can anyone please show me what I need to type in order to make the chip repeat it 32 times. By the way, my code works well but as I mentioned, what if I wanted to repeat the code 100 time...I will be way to long if I copy and paste it 100 times.
Thanks in advance.
Here is the code....
void main()
{
ADCON1=7; //Turn OFF analog
INTCON2=0; //pull ups enable
TRISC.F0 = 0;
TRISC.F1 = 0;
TRISC.F2 = 0;
TRISC.F3 = 0;
TRISB.F0 = 1;
TRISB.F1 = 1;
do
{
if(PORTB.F0 == 0 )
{
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
}
if(PORTB.F1== 0 )
{
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00001100;
Delay_ms(500);
PORTC = 0b00001001;
Delay_ms(500);
PORTC = 0b00000011;
Delay_ms(500);
PORTC = 0b00000110;
Delay_ms(500);
PORTC = 0b00001100;
}
}
while(1); // loop executed infinite times
}
repeat a code a certain amount of times
Post your requests and ideas for the mikroElektronika website & forums.
Author
Message
-
- Posts: 1
- Joined: 21 Feb 2023 09:59
-
- Posts: 96
- Joined: 09 Apr 2021 20:37
Re: repeat a code a certain amount of times
#3 Post by frank.malik » 22 Feb 2023 08:55
Hi samdreeze1,
it seems that you like to produce a specific pattern on PortC, with a delay of 500ms between each new value.
What about placing everything in a table, and get the pattern values from this table?
This is not exactly the solution, but should give you some ideas.
it seems that you like to produce a specific pattern on PortC, with a delay of 500ms between each new value.
What about placing everything in a table, and get the pattern values from this table?
This is not exactly the solution, but should give you some ideas.
Code: Select all
uint8_t pattern_value[] = {
0b00000011,
0b00001001,
0b00001100,
...
} ;
if(PORTB.F1== 0 )
{
for ( i=0 ; i<32 ; i++ )
{
PORTC = pattern_value[i] ;
Delay_ms(500);
}
}
Kind regards
Frank
Fusion for STM32 v8, STM32F407ZG@168MHz, 4" TFT capacitive
mikromedia 3, PIC32MZ2048EFH100@200MHz, 3" TFT capacitive
NECTO Studio 3.0.0, mikroC AI for ARM/PIC32, mikroSDK v.2.7.2
Frank
Fusion for STM32 v8, STM32F407ZG@168MHz, 4" TFT capacitive
mikromedia 3, PIC32MZ2048EFH100@200MHz, 3" TFT capacitive
NECTO Studio 3.0.0, mikroC AI for ARM/PIC32, mikroSDK v.2.7.2
Return to “Website & Forums Wishlist”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects