My Logo & Home Link Answers Coding Examples
Help in Electronics
IT logo & Link

   
 

/**************************************** *This program starts a list of struct * *items, adding a new item every time a * *neg edge is received on P1.0 and * *populates the item with data from P0. * *when there is no room left for another * *item, an error is sent on P1.7 * ****************************************/ #include <reg51.h> #include <stdlib.h> struct listItem{ char dataField; struct listItem* next; }; sbit addOne = P1^0; sbit error = P1^7; int main (void) { struct listItem* newItem; struct listItem* head = 0; error = 0; init_mempool((void xdata*) 0x100, 50); while (error == 0){ while (addOne == 0){} while (addOne == 1){} newItem = (struct listItem*) malloc (sizeof(struct listItem)); if (newItem ==0){ error = 1; } else { newItem -> dataField = P0; newItem -> next = head; head = newItem; } } return 0; }
 

Valid XHTML 1.0 Transitional