Based on up-cup6410 illumination experiment completed

Source: Internet
Author: User

Remote illumination Experiment

Experimental Purpose:

Realize remote lighting, through the GPRS self-debugging software to send information to complete the Intelligent furniture remote lighting experiment.

1. Custom ARM Systems

Use Uboot data to bring your own! In the kernel to add pl2303 serial drive, the use of the U port to the serial port, because I use the ARM board, the serial port is not enough, also need a serial port to support the following 430 single-chip microcomputer, through 430 to control the lights of the furniture.

On the action:

Kernel modification:

To the Linux kernel directory make Menucofig

Device DRIVERS-->USB support-->usb Serial Converter Support---> "*" USB CP2101 UART Bridge Controller

Then quit saving!

Make clean

Make done!

Create a file system, set up the boot program

Modify the/etc/profile file, add the command to run my program (./start)

The cross-compiled program, placed in the specified folder, boot from the start is good.

Code for Internet connection:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>

int set_opt (int fd,int nspeed,int Nbits,char nevent,int nstop)
{
struct Termios newtio,oldtio;
if (tcgetattr (fd,&oldtio)! = 0)
{
Perror ("Setupserial 1");
return-1;
}
Bzero (&newtio,sizeof (Newtio));//Å angeled 儴 optin sentence negative 0
Newtio.c_cflag |= clocal | Cread;
Newtio.c_cflag &= ~csize;

Switch (nBits)
{
Case 7:
Newtio.c_cflag |= CS7;
Break
Case 8:
Newtio.c_cflag |= CS8;
Break
}
Switch (nevent)
{
Case ' O ':
Newtio.c_cflag |= Parenb;
Newtio.c_cflag |= parodd;
Newtio.c_iflag |= (INPCK | Istrip);//Pot rudder 牎 nan? Break
Case ' E ':
Newtio.c_iflag |= (INPCK | Istrip);
Newtio.c_cflag |= Parenb;
Newtio.c_cflag |= ~parodd;//Lian Andychia 牎 nan? Case ' N ':
Newtio.c_cflag &= ~parenb;
break;//Juan interacted 牎 nan? }
Switch (nspeed)
{
Case 2400:
Cfsetispeed (&newtio,b2400);
Cfsetospeed (&newtio,b2400);
Break
Case 4800:
Cfsetispeed (&newtio,b4800);
Cfsetospeed (&newtio,b4800);
Break
Case 9600:
Cfsetispeed (&newtio,b9600);
Cfsetospeed (&newtio,b9600);
Break
Case 115200:
Cfsetispeed (&newtio,b115200);
Cfsetospeed (&newtio,b115200);
Break

Default:
Cfsetispeed (&newtio,b9600);
Cfsetospeed (&newtio,b9600);
break;
}
if (nstop ==1)
Newtio.c_cflag &= ~CSTOPB;
Else if (nstop ==2)
Newtio.c_cflag |= CSTOPB;
NEWTIO.C_CC [Vtime] = 0;
Newtio.c_cc[vmin] = 0;
Tcflush (Fd,tciflush);
If ((Tcsetattr (fd,tcsanow,&newtio))!=0)
{
Perror ("com set error");
return ( -1);
}
printf ("Set done!\n");
return 0;
}

int open_port (int fd,int comport)
{
Char *dev[]={"/dev/ttyusb0", "/dev/ttysac1", "/dev/ttysac2", " /dev/ttysac3 "};
Long vdisable;
if (comport==1)
{
FD = open ("/dev/ttyusb0", O_RDWR),
if ( -1==FD)
{
Perror ("Can ' t open Serial Port") ;
Return (-1);
}
Else
printf ("Open ttySAC0 >>>>>.. \ n ");
}
Else if (comport==2)
{
FD = open ("/dev/ttysac1", o_rdwr| o_noctty| O_ndelay);

if ( -1 = = FD)
{
Perror ("Can ' t Open Serial Port");
return ( -1);
}
Else
printf ("Open ttysac1klldkkfjkasdjfakl\n");
}
Else if (comport==3)
{
FD = open ("/dev/ttysac2", o_rdwr| o_noctty| O_ndelay);
if ( -1 = = FD)
{
Perror ("Can ' t Open Serial Port");
return ( -1);
}
Else
printf ("Open ttySAC2 ... \ n"); "
}"
Else if (comport = = 4)
{
FD = open ("/dev/ttysac3", O_RDWR | o_noctty| O_ndelay);
if (fd = =-1)
{
Perror ("Can ' t Open serial Port");
return ( -1);
}
Else
printf ("Open ttysac3.......................\n");
}
if (fcntl (fd,f_setfl,0) <0)
printf ("Fcntl falled!\n"),
Else
printf ("Fcntl =%d\n", Fcntl (FD,F_SETFL, 0));
if (Isatty (Stdin_fileno) ==0)
printf ("Standard input was not a terminal device\n");
Else
printf ("Isatty suc Cess!\n ");
printf ("fd-open=%d\n", FD);
return FD;
}



int main (void)
{
int fd,fd1;
int nread,i,nwrite;
Char buff[1];
if ((Fd=open_port (fd,1)) <0)
{
Perror ("Open_port error");
return;
}
if ((I=set_opt (fd,9600,8, ' N ', 1)) <0)
{
Perror ("set_opt error");
return;
}
if ((Fd1=open_port (fd1,2)) <0)
{
Perror ("Open_port ttySAC2 error");
return;
}
if ((I=set_opt (fd1,9600,8, ' N ', 1)) <0)
{
Perror ("Ser_opt 2 Error");
return;
}
Sleep (3);
printf ("FD =%d\n", FD);
printf ("FD1 =%d\n", fd1);
/* for (i=0;i<100;i++)
{
Nread = Write (fd,buff,8);
printf ("Nread =%d,%s\n", nread,buff);
Sleep (1);
}*/
while (1)
{
Sleep (1);
Nread=read (fd1,buff,1);
if (nread! = 0)
{
Nwrite = Write (fd,buff,1);
if (nwrite! = nread)
{
Perror ("error!!!!!!!!!!!");
return;
}
}
}
Close (FD);
Close (FD1);
return;
}

2.430 single-chip microcomputer receives information via UART, on the code

#include <msp430x14x.h>

char i;
int main (void)
{
Stop watchdog timer to prevent time out reset
Wdtctl = Wdtpw + wdthold;
P2dir=0xff;
p2out=0xff;//Initializing the end foot
P3sel |= 0x30;//Pin taken
ME1 |= UTXE0 +urxe0;//Enable
UCTL0 |= CHAR;//8 bit data
UTCTL0 |= ssel0;//Select Crystal Oscillator
ubr00=0x03;
UBR10 = 0x00;
UMCTL0 = 0x4A;
UCTL0 &= ~swrst;
IE1 |= URXIE0 + UTXIE0;
IFG1 &= ~utxifg0;

_BIS_SR (lpm3_bits + GIE);

}
#pragma vector = Uart0rx_vector
__interrupt void Usart0_rx (void)
{
i = RXBUF0;
Switch (i)
{
Case ' 1 ':P 2OUT ^= 0x01;break;
Case ' 2 ':P 2OUT ^= 0x02;break;
Case ' 3 ':P 2OUT ^= 0x04;break;
Case ' 4 ':P 2OUT ^= 0x08;break;
Case ' 5 ':P 2OUT ^= 0x10;break;
Case ' 6 ':P 2OUT ^= 0x20;break;
Case ' 7 ':P 2OUT ^= 0x40;break;
Case ' 8 ':P 2OUT ^= 0x80;break;
Case ' 9 ':P 2OUT |= 0xff;break;
Default:p2out |= 0xff;break;
}
}

3. According to the GPRS serial port I wrote, set the GPRS attribute!

Through the data with the debugging, success!

Based on up-cup6410 illumination experiment completed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.