Skip to content

Commit

Permalink
Improve debugging by using both the LCD and the serial port.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonan CM committed Sep 27, 2013
1 parent aaf6448 commit 7d6ef63
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions gpcore/hostcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@ size_t hostcom_read_cmd(byte_t buf[], size_t size, bool_t *full)

return copied;
}

int hostcom_send(const char * const data, const int size)
{
int sent;
for (sent = 0; sent < size; ++sent)
{
while (U2STAbits.UTXBF); // Wait while the transmit buffer is full
U2TXREG = data[sent];
}
return sent;
}
2 changes: 2 additions & 0 deletions gpcore/hostcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ void __attribute__((__interrupt__)) _U2RXInterrupt(void);
*/
size_t hostcom_read_cmd(byte_t buf[], size_t size, bool_t *full);

int hostcom_send(const char * const data, const int size);

#endif
14 changes: 12 additions & 2 deletions gpcore/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,27 @@ _FGS(CODE_PROT_OFF); //Disable Code Protection
#include "hostcom.h"
#include "../lcd.h"
#include "../types.h"
#include "../macros.h"

#define BUF_SIZE 64

#define LCD_READY "GPMCU ready"
#define MSG_READY "GPMCU ready\n"
#define MSG_RECVD "Received: "

#include <string.h> // debug

int main(void)
{
lcd_setup();
hostcom_setup();
lcd_setup();

// Set up port pin RB0 the LED D3
LATBbits.LATB0 = 0; // Clear Latch bit for RB0 port pin
TRISBbits.TRISB0 = 0; // Set the RB0 pin direction to be an output

lcd_write("GPMCU ready");
lcd_write(LCD_READY);
hostcom_send(MSG_READY, STRLEN(MSG_READY));

while (1)
{
Expand All @@ -46,6 +54,8 @@ int main(void)
{
buf[copied - 1] = '\0';
lcd_write((char *) buf);
hostcom_send(MSG_RECVD, STRLEN(MSG_RECVD));
hostcom_send((char *) buf, strlen((char *) buf));
}
}

Expand Down
6 changes: 6 additions & 0 deletions macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef MACROS_H
#define MACROS_H

#define STRLEN(x) (sizeof(x) - 1)

#endif

0 comments on commit 7d6ef63

Please sign in to comment.