// HiTECH PICC // This program uses the MPLAB SIM to compile and debug // it also uses the USART IO located under Debugger>>Settings>>USART IO // Completed for the 44 pin demo board for the Micro...

1 answer below »
Actually there is two assignments. Only after finishing assignments we can move over to 3. Because both are connected. The software for doing this programming is Mplab x ide. Assignment 2 files are:loopcondition assignment2, assign2.c, loops.c, users.c and usart.h.Rest of files are for assignment 3. Reference style doesn't matter



// HiTECH PICC // This program uses the MPLAB SIM to compile and debug // it also uses the USART IO located under Debugger>>Settings>>USART IO // Completed for the 44 pin demo board for the Micro course. //#define _LEGACY_HEADERS #include #include #include //Configuration bits found in pic16f887.h file // CONFIG1H #pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7) #pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT is always enabled. SWDTEN bit has no effect) #pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled) // Function Prototypes // global declaration for the functions created void setUSART(); // program starts execution here /* This is a program that demonstrates the use of conditional statements, Loops, operators and data types.Use the code provided along with code samples from previous classes (i.e. loops.c, conditions.c, datatypes.c)to finish the LAB1 assign.c program. */ int main(void) { setUSART();// Function call for seting up the UART IO Window capability - will be discussed later. // Define a variable of type char. Name it i char cCount;// define a vartiable of type char, Name it count // define a vartiable of type char, Name it cHeight // define a vartiable of type char, Name it cLength // define a vartiable of type char, Name it cArea // Assign a value to cCount to determine the loop code to execute ***student to change value and run*** // Assign a value of 10 the cLenght // Assign a value of 15 the cHeight // based on the values assigned to variable cCount select an if() condition // Add additional else if() statement code to call the other loop functions if(cCount == 1) { // Perfom a for loop count to 10 // use printf("") to display the iteration number to the UARTIO window on each loop } // add an else if() statement for the while loop code to execute // Perform a while loop count to 8 inside the else if() statement. Uses {} to surround the code // use printf("") to display the iteration number to the UARTIO window on each loop // Add an else condition to calculate the area of a rectangle. Remember to us {} to surround your code // add code to calculate the area of a rectangle // use printf("") to display the result to the UARTIO window printf("Program complete! Press Pause to terminate."); while (1);// infinite loop to pause the program } // ************************************************************************ // Code used to set up the USART ouput for display on the UART output screen // Will be discussed in detail later // ************************************************************************ void setUSART() {// Next four register values are determined from the BAUD rate tables BRGH = 1; // TXSTA Reg, Chooses high speed Baud rate of development BRG16= 0;// BAUDCTL reg. 8-Bit Baud generator is used SPBRG = 51;// Baud selection for 9600. Obtained from the BAUD Rates for asynchronous modes tables SYNC = 0;// TXSTA, Set the TX Control to asynchronous mode. TXEN = 1;// Set to 1 to enable the USART Transmitter INTCON = 0x00;// INTCON, Enables interrupts General an peripheral. //TXIF = 0; RX9 =0;// RCSTA, Sets 8 BIT reception SPEN =1;// RCSTA, Serial Port enabled CREN = 0;// RCSTA, continuous receive disabled } // HiTECH PICC // This program uses the MPLAB SIM to compile and debug // it also uses the USART IO located under Debugger>>Settings>>USART IO // Completed for the 44 pin demo board for the Micro course. //#define _LEGACY_HEADERS #include #include #include // PIC18F45K20 Configuration Bit Settings // 'C' source line config statements #include // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG1H #pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7) #pragma config WDTEN = ON // Watchdog Timer Enable bit (WDT is always enabled. SWDTEN bit has no effect) #pragma config LVP = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled) // Function Prototypes void setUSART(); // program starts execution here /* This is a program that demonstrates the use of confditional statements programmer for doing calculations and bit manipulations.*/ int main(void) { // Variable declarations char forCount, whileCount, doWhileCount; // Declare 3 loop count variables char j, k;// Declare 3 loop iterators as type char time_t t; int randnum = 0; int targnum = 40; int i; // Variable assignments forCount = 15;// Assign values to the loop terminators variables whileCount = 8; doWhileCount = 10; i = j =0;// Initialize loop iterators to 0 k = 100; setUSART();// Call subroutine to set up SIM Uart1 window // For Loop example for(i = 0;i<=forcount;i++) {="" printf("the="" for="" loop="" value="" of="" i="%d\n"," i);="" }="" while="" loop="" example="" while(j=""><= whilecount)="" {="" printf("while="" loop="" number="" %d\n",j);="" j++;="" }="" do...while="" loop="" example="" do="" {="" printf("do="" while="" loop="" number="%d\n"," k);="" k++;=""><=dowhilecount); srand(null);="" for(i=""><1000 &&="" (randnum="" !="targnum);i++)" {="" randnum="rand()%49;" }="" if(i="=" 1000)="" printf("unable="" to="" produce="" the="" number="" in="" 1000="" attempts\n\n");="" else="" printf("the="" number="" of="" loops="" required="" to="" produce="" %d="%d\n\n",targnum," i);="" printf("\n****finished!!!****\npress="" pause="" and="" reset="" to="" terminate="" and="" reset="" the="" program.\n");="" while(1);;="" }="" code="" used="" to="" set="" up="" the="" usart="" ouput="" for="" display="" on="" the="" uart="" output="" screen="" -="" will="" be="" discussed="" in="" detail="" later="" void="" setusart()="" {="" next="" four="" register="" values="" are="" determined="" from="" the="" baud="" rate="" tables="" brgh="1;" txsta="" reg,="" chooses="" high="" speed="" baud="" rate="" of="" development="" brg16="0;" baudctl="" reg.="" 8-bit="" baud="" generator="" is="" used="" spbrg="51;" baud="" selection="" for="" 9600.="" obtained="" from="" the="" baud="" rates="" for="" asynchronous="" modes="" tables="" sync="0;" txsta,="" set="" the="" tx="" control="" to="" asynchronous="" mode.="" txen="1;" set="" to="" 1="" to="" enable="" the="" usart="" transmitter="" intcon="0x00;" intcon,="" enables="" interrupts="" general="" an="" peripheral.="" txif="0;" rx9="0;" rcsta,="" sets="" 8="" bit="" reception="" spen="1;" rcsta,="" serial="" port="" enabled="" cren="0;" rcsta,="" continuous="" receive="" disabled="" }="" microcontroller="" programming="" -="" class="" exercise="" 2b="" microcontroller="" programming="" -="" class="" exercise="" 2b="" nova="" scotia="" community="" college="" waterfront="" campus="" electronics="" engineering="" technician="" _______________________________________________________________="" eetd="" 4001="" microcontroller="" programming="" i="" assignment="" #="" 2="" –="" loops="" and="" conditional="" statements="" date="" assigned:="" ___________________________="" due="" date:="" ___________________________="" note:="" late="" assignments="" will="" be="" subject="" to="" a="" 20="" percent="" per="" day="" penalty="" ___________________________________________________________________="" student="" name="" _______________________________________="" student="" id="" _______________________________________="" filename(s)="" _______________________________________="" _________________________________________________="" _________________________________________________="" _________________________________________________="" _________________________________________________="" date="" submitted="" ________________________________________="" mark="" ________="" the="" purpose="" of="" this="" programming="" lab="" is="" to="" have="" the="" student="" use="" the="" datatypes,="" operators,="" conditions="" and="" loops="" code="" given="" in="" previous="" lessons="" to="" write="" a="" program="" to="" perform="" the="" following="" operation:="" 1.="" as="" a="" starting="" point,="" use="" the="" sample="" piece="" of="" code="" provided="" in="" brightspace="" located="" in="" the="" introduction="" to="" ansi="" c="" –="" conditional="" statements="" section,="" assignment="" 2="" –="" loops/conditions="" source="" code.="" 2.="" use="" the="" handout="" that="" you="" were="" given="" ‘creating="" a="" project="" with="" uart="" capability’="" to="" create="" a="" project="" using="" the="" assing2b.c="" code="" provided.="" 3.="" once="" the="" new="" project="" has="" been="" created,="" compile="" the="" code="" to="" ensure="" the="" project="" created="" is="" a="" working="" project.="" once="" it="" is="" working="" perform="" the="" following="" steps.="" note:="" pay="" attention="" to="" the="" comments="" in="" the="" code.="" they="" will="" direct="" you="" as="" to="" what="" is="" required="" at="" certain="" steps="" 4.="" define="" a="" variable="" of="" type="" char="" and="" name="" it="" ccount.="" 5.="" define="" a="" loop="" iterator="" variable="" of="" type="" char="" and="" name="" it="" i.="" 6.="" define="" a="" length="" variable="" of="" type="" char="" and="" name="" it="" cheight.="" 7.="" define="" a="" width="" variable="" of="" type="" char="" and="" name="" it="" cwidth.="" 8.="" define="" an="" area="" variable="" of="" type="" char="" and="" name="" it="" carea.="" 9.="" assign="" the="" declared="" variables="" the="" following="" values="" a.="" ccount="1" (count="" will="" be="" updated="" for="" the="" different="" conditions)="" b.="" i="0" c.="" cwidth="15" d.="" clength="10" 10.="" the="" ccount="" variable="" will="" be="" used="" as="" follows:="" a.="" if="" ccount="" equals="" 1="" then="" the="" first="" if()="" condition="" runs="" b.="" if="" ccount="" equals="" 2,="" the="" first="" else="" if()="" condition="" will="" run.="" c.="" if="" ccount="" is="" equals="" 3,="" the="" second="" else_if()="" will="" run="" d.="" if="" ccount="" is="" greater="" than="" three="" or="" less="" than="" one,="" the="" else="" condition="" will="" run="" 11.="" to="" do="" this,="" add="" a="" conditional="" if()/else="" if()/else="" statements="" to="" interrogate="" the="" value="" of="" ccount="" to="" determine="" what="" type="" of="" loop="" you="" will="" run.="" a.="" if="" the="" first="" condition="" is="" satisfied="" run="" a="" for-loop="" of="" 10="" b.="" if="" the="" second="" condition="" is="" satisfied="" run="" a="" while-loop="" of="" 8="" c.="" if="" the="" third="" condition="" is="" satisfied,="" run="" a="" do-while="" loop="" of="" 6="" d.="" if="" none="" of="" the="" conditions="" are="" satisfied,="" calculate="" the="" area="" of="" a="" rectangle="" with="" a="" length="" equal="" to="" 10="" and="" a="" width="" of="" 15="" (see="" defined="" variable="" values).="" (see="" example="" below).="" if="" (count="=" 1)="" {="" for(iterator="" ;condition;="" increment)="" run="" a="" for="" loop="" for="" a="" count="" of="" 10.="" printf(“value="" of="" the="" for="" loop="%d\n”,iterator);" }="" else="" if="" (condition)="" {="" }="" and="" so="" on…="" 12.="" the="" value="" of="" the="" count="" and="" the="" type="" of="" loop="" it="" was="" counted="" in="" should="" be="" printed="" to="" the="" uart="" io="" window="" as="" shown="" above.="" you="" can="" also="" use="" the="" printf="" ()="" statements="" in="" the="" code="" you="" were="" given="" as="" examples="" 13.="" evaluation="" of="" your="" program="" will="" be="" determined="" from="" your="" code="" and="" through="" demonstration="" of="" a="" working="" program.="" a.="" remember="" to="" format="" and="" comment="" your="" code="" as="" per="" the="" guidelines="" discussed="" in="" previous="" lectures="" submission:="" ·="" combine="" a="" copy="" of="" your="" source="" (.c)="" code="" and="" uart1="" output="" window="" in="" an="" msword="" document="" and="" submit="" to="" brightspace.="" eetd="" 4001="" page="" 2="" #include=""> #include #include "usart.h" void putch(unsigned char byte) { /* output one byte */ while(!TXIF)/* set when register is empty */ continue; TXREG = byte; } unsigned char getch() { /* retrieve one byte */ while(!RCIF)/* set when register is not empty */ continue; return RCREG; } unsigned char getche(void) { unsigned char c; putch(c = getch()); return c; } #ifndef _SERIAL_H_ #define _SERIAL_H_ #define BAUD 9600 #define FOSC 4000000L #define NINE 0 /* Use 9bit communication? FALSE=8bit */ #define DIVIDER ((int)(FOSC/(16UL * BAUD) -1)) #define HIGH_SPEED 1 #if NINE == 1 #define NINE_BITS 0x40 #else #define NINE_BITS 0 #endif #if HIGH_SPEED == 1 #define SPEED 0x4 #else #define SPEED 0 #endif #if defined(_16F87) || defined(_16F88) #define RX_PIN TRISB2 #define TX_PIN TRISB5 #else #define RX_PIN TRISC7 #define TX_PIN TRISC6 #endif /*
Answered 2 days AfterOct 26, 2021

Answer To: // HiTECH PICC // This program uses the MPLAB SIM to compile and debug // it also uses the USART IO...

Darshan answered on Oct 29 2021
133 Votes
// HiTECH PICC
// This program uses the MPLAB SIM to compile and debug
// it also uses the USART IO locate
d under Debugger>>Settings>>USART IO
// Completed for the 44 pin demo board for the Micro course.
//#define _LEGACY_HEADERS
#include
#include
#include
//Configuration bits found in pic16f887.h file
// CONFIG1H
//#pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
//#pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT is always enabled. SWDTEN bit has no effect)
//#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
// Function Prototypes
// global declaration for the functions created
void setUSART();
// program starts execution here
/* This is a program that demonstrates the use of conditional statements,
Loops, operators and data types.Use the code provided along with code samples from previous
classes (i.e. loops.c, conditions.c, datatypes.c)to finish the LAB1 assign.c program.
*/
int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here