Ti Manual
Ti Manual
Step7: Now click Build All under project to build the project to check for any errors.
Step8: Now click Debug under run to debug the program step by step before executing in
the device.
Step9: The compiler goes to debug mode and Green color LED glows in the launch board
resembling that the launch board is in debug mode.
Note: Notice the pointer point the main function of the program as indicated in the arrow
mark below.
Step10: Now press F5(Step) for step by step execution of the program and notice that
depending upon the step by step execution the pointer moves one line after the another in
the program and the launch board output executes depending upon the instruction executed
in the program for example the above program is a LED blinking program in which Port2 is
made as GPIO output in the line 6 to 8 and is made high at line 11 hence if line 11 is
executed the P2.1 GREEN LED starts to glow in the launch board. Hence using debug mode
real time execution can be done step by step.
Step11: Click the red termination button to terminate the debug session and move to
continuous execution mode
Note: the GREEN debug led stops and the program starts to execute continuously in
this case the P2.1 starts to blink.
METHOD 2
1. LED BLINKING
#include <ti/devices/msp432p4xx/driverlib/driverlib.h> //header file
int main(void)
{
int i;
GPIO_setAsOutputPin(GPIO_PORT_P6,GPIO_PIN4); //port6,4th pin output pin
while(1)
{
GPIO_setOutputHighOnPin(GPIO_PORT_P6,GPIO_PIN4); //P6.4 Is high
for(i=0;i<300000;i++);
GPIO_setOutputLowOnPin(GPIO_PORT_P6,GPIO_PIN4); //P6.4 Is low
}
}
1. LED BLINKING
#include "msp.h" //header file
void main(void) //main function
{
int i;
P6->SEL1 &= ~0x10; //port6,4th pin as GPIO Pin
P6->SEL0 &= ~0x10;
P6->DIR |= 0x10; //set port6,4th pin consider as output
while(1)
{
P6->OUT |=0x10; //led on
for(i=0;i<300000;i++);
P6->OUT &=~0x10; //led of
}
}
#include <msp.h>
void delay(unsigned int time) //delay function
{
int j,i;
for(j=0;j<time;j++)
{
for(i=0;i<1000;i++);
}
}
void send(int address, int data) //send data function
{
int j,temp;
P4->OUT &= ~0X10; //serial clock low
P4->OUT &= ~0X20; //chip select low
for (j = 0; j < 8; j++) //Transfer of 8 bits
{
temp = address;
if ((temp & 0x80) == 0x80) //if MSB of data is high
{
P4->OUT |= 0X80; //data is high
}
else
{
P4->OUT &= ~0X80; //data is low
}
address = address<<1; //Left shift of data
P4->OUT |= 0X20; //serial clock high
delay(1);
P4->OUT &=~ 0X20; //serial clock low
delay(1);
}
for (j = 0; j < 8; j++) //Transfer of 8 bits
{
temp = data;
if ((temp & 0x80) == 0x80) //if MSB of data is high
{
P4->OUT |= 0X80; //data is high
}
else
{
P4->OUT &= ~0X80; //data is low
}
data= data<<1; //Left shift of data
P4->OUT|=0X20; //serial clock high
delay(1);
P4->OUT&=~0X20; //Serial clock low
delay(1);
}
P4->OUT|=0X10; //chip select high
delay(1);
P4->OUT&=~0X10; //chip select low
delay(1);
}
void maxiniti()
{
int i;
int a[3]={0x0C,0x0A,0x09};
int b[3]={0x01,0x03,0xFF};
for(i=0;i<3;i++)
{
send(a[i],b[i]);
delay(1);
}
}
void main()
{
int i,k,tmp,n,dispv;
P4->SEL1 &= ~0x10;
P4->SEL0 &= ~0x10;
P4->SEL0 &= ~0x20;
P4->SEL1 &= ~0x20;
P4->SEL0 &= ~0x80;
P4->SEL1 &= ~0x80;
#include "msp.h"
void delay_ms() // 1ms delay function
{
int i,j;
for(i=0;i<1;i++)
{
for(j=0;j<3000;j++);
}
}
void delay_us() //1us delay function
{
int i,j;
for(i=0;i<1;i++)
{
for(j=0;j<3;j++);
}
}
void i2ciniti()
{
P4->OUT|=0X04; //SDA As high
P4->OUT|=0X01; //SCL As high
}
void i2cstart()
{
P4->OUT&=~0X04; //SDA As low
delay_ms();
P4->OUT&=~0X01; //SCL As low
}
void send_data(int data_)
{
int i,temp,temp1;
for(i=0;i<8;i++)
{
temp=data_;
temp1=temp&0x80;
P4->OUT&=~0X01; //SCL As low
if(temp1==0x80)
{
P4->OUT|=0X04; //SDA As high
}
else
{
P4->OUT&=~0X04; //SDA As low
}
delay_us();
data_=data_*2;
P4->OUT|=0X01; //SCL As high
}
delay_us();
P4->OUT&=~0X01; //SCL As low
delay_us();
P4->OUT|=0X04; //SDA As high
delay_us();
P4->OUT|=0X01; //SCL As high
delay_us();
P4->OUT&=~0X01; //SCL As low
delay_us();
}
void i2cstop()
{
P4->OUT&=~0X01; //SCL As low
delay_ms();
P4->OUT&=~0X04; //SDA As low
delay_ms();
P4->OUT|=0X01; //SCL As high
delay_ms();
P4->OUT|=0X04; //SDA As high
}
void lcddata(char dat)
{
char hin, lon;
char rs = 0x01; //assign rs as high
hin = dat & 0xF0; // masking higher nibble bit
lon = (dat << 4) & 0xF0; // masking lower nibble bit
i2cstart();
send_data(0x4E); /*0100 1110 -- LHLL HHHL O th bit is low so
it's write operation, (1st,2nd,3rd) bit is high so A0,A1,A2 is high so choose the
control Command of pcf8457 is 4E*/
send_data(hin | rs | 0x04 | 0x08); //enable pin high for higher nibble bit
delay_us();
send_data(hin | rs | 0x00 | 0x08); //enable pin low for higher nibble bit
delay_us();
send_data(lon | rs | 0x04 | 0x08); //enable pin high for lower nibble bit
delay_us();
send_data(lon | rs | 0x00 | 0x08); //enable pin low for lower nibble bit
i2cstop();
}
void lcdcmd(char cmd)
{
char hin, lon;
char rs = 0x00; //assign rs as low
hin = cmd & 0xF0; // masking higher nibble bit
lon = (cmd << 4) & 0xF0; // masking lower nibble bit
i2cstart();
send_data(0x4E); /*0100 1110 -- LHLL HHHL O th bit is low so
it's write operation, (1st,2nd,3rd) bit is high so A0,A1,A2 is high so choose the
control Command of pcf8457 is 4E*/
send_data(hin | rs | 0x04 | 0x08); //enable pin high for higher nibble bit
delay_us();
send_data(hin | rs | 0x00 | 0x08); //enable pin low for higher nibble bit
delay_us();
send_data(lon | rs | 0x04 | 0x08); //enable pin high for lower nibble bit
delay_us();
send_data(lon | rs | 0x00 | 0x08); //enable pin low for lower nibble bit
i2cstop();
}
void lcdinit()
{
delay_ms();
i2cstart();
send_data(0x4E); /*0100 1110 -- LHLL HHHL O th bit is low so it's write
operation, (1st,2nd,3rd) bit is high so A0,A1,A2 is high so choose the control
Command of pcf8457 is 4E*/
delay_ms();
send_data(0x2C);
delay_us();
send_data(0x28); // 4bit mode operation
i2cstop();
delay_ms();
lcdcmd(0x01); //clear the screen
lcdcmd(0x06); //entry mode
}
void main(void)
{
i2ciniti();
lcdinit();
lcdcmd(0x80);
for(k=0;k<15;k++)
{
lcddata(first[k]);
}
while(1);
}