struct patient
{
char Lastname;
char Firstname;
char symptoms;
int cardnumber;
int patientnumber;
} ;
int choice;
static FILE uart00 = {0};
void USART0_init(void) {
UCSR0A = 0; //single transmission speed, multiprocessor disabled
UCSR0B = (1<<RXEN0) | (1<<TXEN0); //enable Rx & Tx
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); //asynchronous, no parity, 1 stop, 8 bits
UBRR0 = 103; //load the value for 9600 bps baud rate into whole UBRR register
fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW); //Associate RX and TX functions with stdin/stdout
stdin= stdout = &uart00 ; //the uart is defined as the standard inputa/output device
}
static int RX(FILE *stream) {
//do nothing until data is received and is ready to be read from UDR0; wait for USART RX Complete flag
while ((UCSR0A & (1 << RXC0)) == 0) {};
//when flag is set read data from USART UDR0 register and return it
return(UDR0);
}
static int TX(char TXData , FILE *stream) {
//do nothing until UDR0 is ready for more data to be written to it; wait for USART UDRE flag
while ((UCSR0A & (1 << UDRE0)) == 0) {};
//when flag is set send data by placing the byte into UDR0
UDR0 = TXData;
return 0 ;
}
void setup(void)
{
USART0_init();
fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW); //Associate RX and TX functions with stdin/stdou
stdin= stdout = &uart00 ; //the uart is defined as the standard inputa/output device
//No need to make PH5, PH6 or PB4 as inputs, by default it is input at powerup
PORTB |= (1<<PB4); //Enable internal resistor on PB4 input
PORTH |= (1<<PH5)| (1<<PH6); //Enable internal resistor on PH5 and PH6 input
}
void loop(void)
{
typedef struct patient patientname;
printf ("\nSER202, Programming for emebbeded systems");
printf("\nThomas Smith");
printf("\n217068347");
printf("\n----------------");
while(1)
{
printf("\nSelect one of the following numbers and press enter");
printf("\n1.Patient Details"); //Assume we will have maximum 8 patients
printf("\n2.Allocate Patient to Doctor"); //Jerome Mcclain, Teresita Lieu, Rocky Michael (Doctors names)
printf("\n3.Call Patient"); //Call the nextpatient and send them to see their Doctor
printf("\n4.Report"); //Generate a clinic financial report
printf("\n----------------");
scanf("%d",&choice);
switch (choice)
{
case 1:
{
printf ("\nEnter the following and press enter");
printf ("\nFirst Name and last name"); //First Name Last Name, max 25characters, show full name to user
scanf ("%s %s",patientname.Firstname,patientname.Lastname); // First name stored and last name stored
printf ("\nFull name:%s %s", patientname.Firstname,patientname.Lastname); //Full name to be shown
printf ("\nMedicare Card Number:"); //5digits entered, show digits to user, Receive the digits as a string of 5characters
scanf("%s",patientname.cardnumber); // Medicare card number stored
printf("%s\n",patientname.cardnumber); // Medicare number shown
printf ("Symptoms:"); //Comma separated list of symptoms, max 25 characters, show symptoms to user
scanf ("%s", patientname.symptoms); // Symtoms for pateient stored
printf ("%s\n", patientname.symptoms); // Symtoms shown on screen
printf ("Patient Number:"); //Generate patient number and display it this number should be an integer equal to the number of patients currently in the system + 1
scanf ("%s",patientname.patientnumber); // Patient number stored
printf ("%s\n",patientname.patientnumber); // Patient number shown
}
break;