The code for the Nokia 5110/PSoC 4100
/* ========================================
M. Ray Burnette - Nokia B/W GLCD + 6 Channel A-D
20140725 - Please reference "Credits_Licenses.txt"
All code by Ray is Public Domain
Note: Modified heap and stack constants
Flash used: 10424 of 32768 bytes (31.8 %).
SRAM used: 1888 of 4096 bytes (46.1 %).
* ========================================
*/
#define GLCD_DEVICE_PSOC //PSoC
#define GLCD_CONTROLLER_PCD8544 //Controller
#define CR 0x0D
#define LF 0x0A
#define CLEAR_SCREEN (0x0C)
#define CONVERT_TO_ASCII (0x30u)
#define NewLine() UART_UartPutChar(CR); UART_UartPutChar(LF); // Used to insert a CR/LF
#include <project.h>
#include "glcd/glcd.h"
#include "glcd/fonts/font5x7.h" // Fonts for Nokia 5110
#include <ADCmux.h> // structures
// Function Prototypes
void UART_UartPutString();
void initHarware()
{
UART_Start(); // Property sheet sets default @9600 BAUD
CyGlobalIntEnable; //Enable Interrupts
glcd_init();
glcd_set_contrast(75); //0== light 100==full black
// remaining hardware initializations
ADCmux_Start();
ADCmux_StartConvert();
CyGlobalIntEnable;
GLCD_TEXT_INIT();
}
void putdata ( void* p, char c) // part of tinyprintf() see "PrintExamples.txt"
{
UART_UartPutChar(c);
}
/* tinyprintf supports the following formats:
'd' int as a signed decimal number
'u' uint as a decimal number
'c' character
's' null terminated string
'x' / 'X' hexadecimal with lower / upper case letters */
// Global variables
int8 d = -10;
uint8 u = 127;
char c = 'c'; // uint8_t c = 32;
uint8_t len = GLCD_LCD_WIDTH / 6;
// char string[GLCD_LCD_WIDTH / 6 + 1]; // LCD line buffer
// char buffer[50]; // serial tty original line buffer
char buffer[GLCD_LCD_WIDTH / 6 + 1];
// Variables for A--> D results Ports P2[0] - P2[5]
int16 result0;
int16 result1;
int16 result2;
int16 result3;
int16 result4;
int16 result5;
int main()
{
// activate PSoC hardware modules
initHarware();
// Announce activity to PC over serial console
UART_UartPutString("Hardware Configured\n"); NewLine(); NewLine();
init_printf(NULL, putdata);
for(;;)
{
// Read all 6 of the AD channels and output
// Single ended 4096 slices = 2.048V max = 0.500mV / slice
ADCmux_IsEndConversion(ADCmux_WAIT_FOR_RESULT); // blocking
result0 = ADCmux_GetResult16(0) / 2 ;
sprintf(buffer, "Ch0 mV = %d", result0);
UART_UartPutString(buffer); NewLine();
buffer[len] = '\0';
GLCD_WRITE(buffer);
result1 = ADCmux_GetResult16(1) / 2 ;
sprintf(buffer, "Ch1 mV = %d", result1);
UART_UartPutString(buffer); NewLine();
buffer[len] = '\0';
GLCD_WRITE(buffer);
result2 = 0.5 * ADCmux_GetResult16(2) / 2 ;
sprintf(buffer, "Ch2 mV = %d", result2);
UART_UartPutString(buffer); NewLine();
buffer[len] = '\0';
GLCD_WRITE(buffer);
result3 = ADCmux_GetResult16(3) / 2 ;
sprintf(buffer, "Ch3 mV = %d", result3);
UART_UartPutString(buffer); NewLine();
buffer[len] = '\0';
GLCD_WRITE(buffer);
result4 = ADCmux_GetResult16(4) / 2 ;
sprintf(buffer, "Ch4 mV = %d", result4);
UART_UartPutString(buffer); NewLine();
buffer[len] = '\0';
GLCD_WRITE(buffer);
result5 = ADCmux_GetResult16(5) / 2 ;
sprintf(buffer, "Ch5 mV = %d", result5);
UART_UartPutString(buffer); NewLine(); NewLine() ;
buffer[len] = '\0';
GLCD_WRITE(buffer);
// glcd_test_tiny_text() ;
CyDelay(5000) ;
}
}