Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
db66dev1_demo1/main.c

===== Description =====

This demo contains some test code for the DB66DEV1 development daughter board. The potentiometer, connected to analog input 3 (old port name X3) controls the frequency of the buzzer connected to port 34 (old port name Y4). This port is configured as a PWM output. The 4 buttons on the DB66DEV1 will simply control LEDs 1 to 4 (on/off when button pressed/depressed). LEDs 5 to 8 run from left to right, incremented each 100ms.

Additionally the System LED blinks every second.

The DB66DEV1 has a potentiometer on port 3 (old port name X3). This port has an ADC (Analog to Digital) converter on all SBC66 Netcruzer boards. The SBC66 Netcruzer boards have 12 Analog input ports, port 0-5 and 30-35 (old port names X0-X5, and Y0-Y5). For details see modtronix.com/product/sbc66ec/ Port 3 is configured as an Analog Inputs. By default the ADC is configured for voltages between 0-2.5V, include "#define ADC_3V3_VREF" in projdefs.h for 0-3.3V range.

The DB66DEV1 has 4 button on ports 30, 31, 32 and 33 (old port names Y0, Y1, Y2 and Y3). They are all configured as inputs.

The DB66DEV1 has 8 LEDs on ports 6, 7, 8, 9, 26, 27, 28, 29 (Old port names X6, X7, X8, X9, T4, T5, T6 and T7). These ports are all configured as outputs.

The DB66DEV1 has a buzzer on port 34 (old port name Y4).

===== Required Hardware =====

The project requires a SBC66 Netcruzer board with an USB Port (not USB Host), AND a DB66DEV1 development board. The DB66DEV1 is plugged into the daughter board connector of the SBC66 board.

===== Building Project =====

This project is located in the "src/demos/db66dev1/db66dev1_demo1" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ECL_R2" for the SBC66ECL Revision 2 board. For details click here A common error is "The system cannot find the path specified". This generally means you don't have the required XC16 compiler version installed. Go to "Project Properties", and select your installed XC16 compiler in the "Project Configuration" section.

===== Programming Board =====

After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.

===== File History =====

2013-05-03, David H. (DH):

#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h" //Required for all Netcruzer projects
#include "nz_db66dev1.h"
int main(void)
{
WORD potValue = 0; //Pwm value from 0 to 100 (0 to 100%)
BYTE ledRotate = 1;
WORD tmrFlashLed = 0; //Timer for flashing system LED
WORD tmrProcessIO = 0; //Timer for processing I/O
nzSysInitDefault(); //Default initialization. All ports inputs. All analog features disabled. Tick 1ms
DIR_SYSLED = OUTPUT_PIN; //Set System LED port as outputs
//Initialize DB66DEV1, all LEDs are output and turned off, Buttons inputs
db66dev1_Init();
adcOpen(ADC_OPEN_A3); //Configure port 3 (old port name X3) as ADC channels
//Configure Port 34 (old port Y4) (Buzzer on DB66DEV1) as PWM channel 1, with default frequency of 16kHz.
//To change the default frequency, Redefine PWM1_FREQ in projdefs.h file for desired
//frequency. For example: #define PWM1_FREQ PWM_FREQ_1600HZ
pwm1OpenDefault(PPS_OUT_34, 0);
while(1)
{
nzSysTaskDefault(); //Main netcruzer task, call in main loop.
//Process I/O every 50ms
if (tick16TestTmr(tmrProcessIO)) {
tick16UpdateTmrMS(tmrProcessIO, 100); //Update timer to expire in 100ms again
//Get the potentiometer analog input, will be a value from 0 to 255
potValue = adcReadChan8Bit(ADC_CH_A3);
//Use 0.1 for duty cycle, so buzzer is not too loud (0.5 is maximum volume)
pwmSetFreqAndDutyCycle(1, (potValue*10)+450, 0.1);
//If potentiometer is 0, turn buzzer off (duty cycle of 0)
if (potValue == 0)
pwmSetDutyCycle(1, 0);
//LEDs 1 to 4 are controlled by buttons 1 to 4
LAT_LED1 = !PIN_BUTTON1; //Turn on LED 1 if button 1 pressed, and off if not
LAT_LED2 = !PIN_BUTTON2; //Turn on LED 2 if button 2 pressed, and off if not
LAT_LED3 = !PIN_BUTTON3; //Turn on LED 3 if button 3 pressed, and off if not
LAT_LED4 = !PIN_BUTTON4; //Turn on LED 4 if button 4 pressed, and off if not
//Rotate LEDs 5 to 8
ledRotate = ledRotate << 1;
if (ledRotate==0x10)
ledRotate = 0x01;
if (ledRotate&0x01) LAT_LED5 = 1; else LAT_LED5 = 0;
if (ledRotate&0x02) LAT_LED6 = 1; else LAT_LED6 = 0;
if (ledRotate&0x04) LAT_LED7 = 1; else LAT_LED7 = 0;
if (ledRotate&0x08) LAT_LED8 = 1; else LAT_LED8 = 0;
}
//Flash system LED every 500ms
if (tick16TestTmr(tmrFlashLed)) {
tick16UpdateTmrMS(tmrFlashLed, 500); //Update timer to expire in 500ms again
LAT_SYSLED = !LAT_SYSLED; //Toggle System LED
}
}//end while
return 0;
}//end main
#if !defined(PPS_OUT_34)
#error "Can not build for this target, it does not have a reconfigurable port 34 (old port name Y4)! This is the case for the SBC66EC Revision 1 board. Select a different Configuration!"
#endif