Lesson KB 03: Data Types and APIs
The PSoC Creator provides some useful APIs that can be used in your code.
- Standard C data types (implicit sizes)
Type Size 
(Bytes)Range Description Precision 
(Decimal place)printf() identifier char 1 unsigned: 0 ... 255 
signed: -128 ... 127Character (ASCII Table) %c short 2 unsigned: 0 ... 65535 
signed:-32,768 ... 32767Standard type specifying 2-byte integers %i int 4 unsigned: 0 ... 4,294,967,295 
signed:-2,147,483,648 ... 2,147,483,647Integer number %i long 4 unsigned: 0 ... 4,294,967,295 
signed:-2,147,483,648 ... 2,147,483,647%i float 4 1.175e-38 ... 3.40e+38 Signal precision floating point number 6 %f double 8 2.3E-308 ... 1.7E+308 Double precision floating point number 15 %f long double 8 2.3E-308 ... 1.7E+308 %f enum 1 
21 byte if enum < 256 
2 bytes if enum > 256 0 ... 65535Used to define a list of aliases that represent integers  - Cypress-defined data types
Type Description char8 8-bit (signed or unsigned, depending on the compiler selection for char) uint8 8-bit unsigned integer uint16 16-bit unsigned integer uint32 32-bit unsigned integer int8 8-bit signed integer int16 16-bit signed integer int32 32-bit signed integer float32 32-bit float float64 64-bit float int64 64-bit signed uint64 64-bit unsigned  - Cypress-defined hardware register types
Type Description reg8 Volatile 8-bit unsigned reg16 Volatile 16-bit unsigned reg32 Volatile 32-bit unsigned  - Types available through <stdint.h>
Type Description uint8_t 8-bit unsigned integer uint16_t 16-bit unsigned integer uint32_t 32-bit unsigned integer uint64_t 64-bit unsigned integer int8_t 8-bit signed integer int16_t 16-bit signed integer int32_t 32-bit signed integer int64_t 64-bit signed integer  - Delay Functions
Function Prototype Arguments Description void CyDelay(uint32 milliseconds) uint32 milliseconds – 
Number of milliseconds to delayDelay by the specified number of milliseconds. Ex. To delay 2.5 second → CyDelay(2500); void CyDelayUs(uint32 microseconds) uint32 microseconds – 
Number of microseconds to delayDelay by the specified number of microseconds. Ex. To delay 500 microsecond → CyDelayUs(500); void CyDelayFreq(uint32 freq) uint32 freq – 
Bus clock frequency in Hz;
0: Use default value
Nonzero: Set freq valueSets the Bus Clock frequency to calculate the number of cycles needed to implement a delay with CyDelay or CyDelayUs functions. 
By default, the frequency used is based on the value determined by PSoC Creator at build time.void CyDelayCycles(uint32 cycles) uint32 cycles – 
Number of cycles to delay (0 ~ 32)Delay by the specified number of cycles using a software delay loop.  - Macro statements
CyGlobalIntEnable Enables interrupts using the global interrupt mask CyGlobalIntDisable Disable interrupts using the global interrupt mask  
Here, lists some useful defines:
/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#ifndef __MYDEFINES_H
#define __MYDEFINES_H
#include  <stdint.h>
#include  <stdbool.h>
#include  <stdlib.h>
#include  <string.h>
#include  <math.h>
#define  HIGH           0x1
#define  LOW            0x0
#define  INPUT          0x0
#define  OUTPUT         0x1
#define  PI             3.1415926535897932384626433832795
#define  HALF_PI        1.5707963267948966192313216916398
#define  TWO_PI         6.283185307179586476925286766559
#define  DEG_TO_RAD     0.017453292519943295769236907684886
#define  RAD_TO_DEG     57.295779513082320876798154814105
#define  MIN(a,b)       ((a)<(b)?(a):(b))
#define  MAX(a,b)       ((a)>(b)?(a):(b))
#define  ABS(x)         ((x)>0?(x):-(x))
#define  CONSTRAIN(amt,low,high)  ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define  ROUND(x)       ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define  RADIANS(deg)   ((deg)*DEG_TO_RAD)
#define  DEGREES(rad)   ((rad)*RAD_TO_DEG)
#define  SQ(x)          ((x)*(x))
#define  BCD2DEC(bcd)   ((bcd >> 4) * 10 + (bcd & 0x0F))
#define  DEC2BCD(dec)   (((dec / 10) << 4 ) | (dec % 10))
#define  LOWBYTE(w)     ((uint8_t) ((w) & 0xff))
#define  HIGHBYTE(w)    ((uint8_t) ((w) >> 8))
#define  _PIN0          0x01
#define  _PIN1          0x02
#define  _PIN2          0x04
#define  _PIN3          0x08
#define  _PIN4          0x10
#define  _PIN5          0x20
#define  _PIN6          0x40
#define  _PIN7          0x80
#define  _BIT0          0x01
#define  _BIT1          0x02
#define  _BIT2          0x04
#define  _BIT3          0x08
#define  _BIT4          0x10
#define  _BIT5          0x20
#define  _BIT6          0x40
#define  _BIT7          0x80
#define  _BIT8          0x100
#define  _BIT9          0x200
#define  _BIT10         0x400
#define  _BIT11         0x800
#define  _BIT12         0x1000
#define  _BIT13         0x2000
#define  _BIT14         0x4000
#define  _BIT15         0x8000
#define  _BIT16         0x10000
#define  _BIT17         0x20000
#define  _BIT18         0x40000
#define  _BIT19         0x80000
#define  _BIT20         0x100000
#define  _BIT21         0x200000
#define  _BIT22         0x400000
#define  _BIT23         0x800000
#define  _BIT24         0x1000000
#define  _BIT25         0x2000000
#define  _BIT26         0x4000000
#define  _BIT27         0x8000000
#define  _BIT28         0x10000000
#define  _BIT29         0x20000000
#define  _BIT30         0x40000000
#define  _BIT31         0x80000000
#define  BITREAD(value, bit)             (((value) >> (bit)) & 0x01)
#define  BITSET(value, bit)              ((value) |= (1UL << (bit)))
#define  BITCLEAR(value, bit)            ((value) &= ~(1UL << (bit)))
#define  BITWRITE(value, bit, bitvalue)  (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
#define  BIT(b)                          (1UL << (b))
typedef  unsigned  int  word
typedef  uint8_t        byte
#endif