ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

Untitled Document
/***************************************************************************
*	Author:	Fred Eady
*	Company:	E D Technical Publications
*	Date:	02/15/01
*	Compiled using CCS PICC
****************************************************************************
* Internal EEPROM Addresses
* User Name 0x00 to 0x1F
* Password 0x20 to 0x3F
* Phone Number 0x40 to 0x4F
***************************************************************************/
#include "f877.h"
#include <16f877.h>
#include "s7600.h"
#include 
#include 
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=7372800)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
#use standard_io(A)
#use standard_io(B)
#use standard_io(C)
#use standard_io(E)
#define esc 0x1B
// PORTA bits
#bit READX = PORTA.1
#bit CS = PORTA.2
#bit RS = PORTA.3
// PORTB bits
#bit CTS = PORTB.2	// When CTS = 0 send is enabled
#bit BUSY = PORTB.3
#bit INT1 = PORTB.4
#bit WRITEX = PORTB.5
// PORTC bits
#bit RESET = PORTC.0
// PORTE bits
#bit MODSEL = PORTE.0
#define MAILPORT_H 0x00	// SMTP IP Port #
#define MAILPORT_L 0x19
#define MYPORT_H 0x1F // My IP Port #
#define MYPORT_L 0x90
// Convert your ISP's IP address to hex and put it here
#define T_Address_1 0xC6	// ISP IP Address 198.69.104.2
#define T_Address_2 0x45
#define T_Address_3 0x68
#define T_Address_4 0x02
char i,j,ch,addr,temp,count,count1,page;
long index, byt_cnt;
char MyIPAddr[4];
char user[33];
char pass[33];
char phone[17];
char mailcode[4];
char chkcode[4];
#include "seiko_ct.c"	// Seiko routines
#include "Int_EE.c"	// Internal EEPROM
#include "get_info.c"	// Get Username, Password, and Phone Number routines
/**************************************************************
** void getcode() **
** Get data from the S-7600A socket buffer ** 
**************************************************************/
void getcode()
{
i=0;
while(!(ReadSeiko(Socket_Config_Status_L)&0x10))
{
printf("Waiting for data\r");
}
while(ReadSeiko(Socket_Config_Status_L)&0x10)
{
while(i < 4)	
{	
temp = ReadSeiko(Socket_Data);
mailcode[i] = temp;
++i;
putc(temp);
}
temp = ReadSeiko(Socket_Data);
putc(temp); 
}
} 
/**************************************************************
** void writetosocket() **
** Write a string to the S-7600A socket buffer ** 
**************************************************************/
void writetosocket(char * txt)
{
i=strlen(txt);
for(j=0; j < i; j++)
WriteSeiko(Socket_Data,user[j]);
}
/**************************************************************
** void main(void) **
**************************************************************/
void main(void)
{
// Intialize PORTs & TRISs
//BIT 1 READX
// 2 CS
// 3 RS
PORTA = 0xF9;	//11111001
//BIT 2 CTS
// 3 BUSY
// 4 INT1
// 5 WRITEX
PORTB = 0x38;	//00111000
//BIT 0 RESET
PORTC = 0x80; //10000000
PORTD = 0x00;	//00000000
//BIT 0 MODSEL
PORTE = 0xFB;	//11111011
TRISA = 0xD1;	//11010001
TRISB = 0x18; //00011000
TRISC = 0x80;	//10000000
TRISD = 0xFF;	//11111111
TRISE = 0x00;	//00000000
ADCON1 = 0x06;	//00000110	all digital to start
ADCON0 = 0;
T1CON = 0x31;	//00110001	Timer1
CTS = 1;	// disable send
Menu();	// Show enter menu
restart:
WriteSeiko(Serial_Port_Config,0x06); // TURN OFF DTR AND RTS
delay_ms(10);
RESET = 0; // RESET THE S-7600A
delay_ms(10);
RESET = 1;
// Set clock divider for 1KHz clock
WriteSeiko(Clock_Div_L,0xE5);
while(ReadSeiko(Clock_Div_L) != 0xE5)	// Detects when reset
WriteSeiko(Clock_Div_L,0xE5);	// is complete
WriteSeiko(Clock_Div_H,0x00);
// Set Baud Rate Divisor for 2400 baud @ 9.828606
WriteSeiko(BAUD_Rate_Div_L,0x5F);
WriteSeiko(BAUD_Rate_Div_H,0x00);
WriteSeiko(Serial_Port_Config,0x00); //TURN ON DTR AND RTS
// Set up MODEM
printf(S_Putc,"~~~+++~~~\r");
printf(S_Putc,"ATZ\r");
//printf(S_Putc,"AT&F\r");
delay_ms(100);
WriteSeiko(PPP_Control_Status,0x01);	// reset PPP
WriteSeiko(PPP_Control_Status,0x00);
WriteSeiko(PPP_Control_Status,0x20);	// set PAP mode
delay_ms(5);
// Determine length of "Username" and write it to the PAP register
// in the S-7600A
ReadIntEE(0, user, 32);	// read 32 byte password from EEPROM address 0x00
i = strlen(user);	// Find actual string length
WriteSeiko(PAP_String,i);	// Write string length to PAP register
// Write "Username" to PAP register in S-7600A
for(j=0; j < i; j++)
WriteSeiko(PAP_String,user[j]);
//Determine length of "Password" and write it to the PAP register
ReadIntEE(0x20, pass, 32);	// read 32 byte username from EEPROM address 0x20
i = strlen(pass);	// Find actual string length
WriteSeiko(PAP_String,i);	// Write string length to PAP register
// Write "Password" to PAP register in S-7600A
for(j=0; j < i; j++)
WriteSeiko(PAP_String,pass[j]);
WriteSeiko(PAP_String,0x00);// Write final NULL character to PAP register
// Read Phone Number from EEPROM
ReadIntEE(0x40, phone, 16); // read 16 byte Phone Number from EEPROM address 0x40
// Send Phone Number to the MODEM
printf(S_Putc,"ATDT");	// Send initial ATDT to indicate tone dial
i = strlen(phone);
for(j=0; j < i; j++)	// Write phone number to modem
S_Putc(phone[j]);
printf(S_Putc,"\r");	// end with CR
delay_ms(5);
// Also Write Phone Number to CRT
printf("%c[2J",esc);	// clear VT100 screen
printf("\rDialing ");	// Write dialing
printf(phone);	// Write phone number
printf("\r");
delay_ms(20000);
WriteSeiko(PPP_Control_Status,0x62);	// Use PAP, enable PPP
WriteSeiko(Serial_Port_Config,0x01);	// turn serial port over to S-7600
delay_ms(5);
// (Register 0x60) wait for PPP to be Up
while(!(ReadSeiko(PPP_Control_Status)&0x01))
delay_ms(5);
while(ReadSeiko(Our_IP_Address_L) == 0);	// detect when ready to proceed
MyIPAddr[0] = ReadSeiko(Our_IP_Address_L);	// Read our assigned IP address
MyIPAddr[1] = ReadSeiko(Our_IP_Address_M);
MyIPAddr[2] = ReadSeiko(Our_IP_Address_H);
MyIPAddr[3] = ReadSeiko(Our_IP_Address_U);
// Print address to the terminal and LCD
printf("\r\nMy address is %u.%u.%u.%u",MyIPAddr[3],MyIPAddr[2],MyIPAddr[1],MyIPAddr[0]);
// Write the preconfigured server IP address to the S-7600A
WriteSeiko(Their_IP_Address_L,T_Address_4);
WriteSeiko(Their_IP_Address_M,T_Address_3);
WriteSeiko(Their_IP_Address_H,T_Address_2);
WriteSeiko(Their_IP_Address_U,T_Address_1);
WriteSeiko(Socket_Index,0x00);	// Use Socket 0
WriteSeiko(Socket_Config_Status_L,0x10);// Reset socket
delay_ms(5);
WriteSeiko(Our_Port_L,MYPORT_L);	// Write the port address
WriteSeiko(Their_Port_L,MAILPORT_L);	// for both the server
WriteSeiko(Our_Port_H,MYPORT_H);	// and the client
WriteSeiko(Their_Port_H,MAILPORT_H);
WriteSeiko(Socket_Config_Status_L,0x02);// Use TCP client mode
WriteSeiko(Socket_Activate,0x01);	// Activate socket
// Loop to wait for socket to be connected with the server
while(1)
{
delay_ms(5);
j = ReadSeiko(Socket_Status_M);
if(j&0x10)
{
i = 0;
printf("\n\rConnected\n\r");
break;
}
else if(j&0xe0)
{
printf("\n\rConnection Error\n\r");
WriteSeiko(Serial_Port_Config,0x06); // TURN OFF DTR AND RTS
delay_ms(10);
RESET = 0;
delay_ms(1);
RESET = 1;
#asm
MOVLW 0x00
MOVWF 0x0A
GOTO 0x00
#endasm
}
}
// SMTP code begins here 
printf("\n\rSocket open and connected\n\r");
getcode();
strcpy(chkcode,"220 ");
// connected to mail server at this point
// identify with HELO
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"HELO ddi.digital.net\r\n");
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
} 
getcode();
strcpy(chkcode,"250 ");
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"MAIL From:\r\n"); 
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
} 
getcode();
strcpy(chkcode,"250 ");
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"RCPT To:\r\n"); 
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
} 
getcode();
strcpy(chkcode,"250 ");
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"DATA\r\n"); 
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
} 
getcode();
strcpy(chkcode,"354 ");
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"From: edtp@ddi.digital.net\r\n");
writetosocket(user);
strcpy(user,"To: fred@edtp.com\r\n");
writetosocket(user);
strcpy(user,"Subject: Internet Engine Mail Test\r\n");
writetosocket(user);
strcpy(user," \r\n"); 
writetosocket(user);
strcpy(user,"The S-7600A/PIC16F877 Internet Engine has just sent you email!\r\n");
writetosocket(user);
strcpy(user,"There is water on the basement floor.\r\n");
writetosocket(user);
strcpy(user,"Your garage door has just been opened.\r\n.\r\n");
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
}
getcode();
strcpy(chkcode,"250 ");
if(strncmp(mailcode,chkcode,3)==0)
{
strcpy(user,"QUIT\r\n"); 
writetosocket(user);
WriteSeiko(TCP_Data_Send,0);
}
getcode();
strcpy(chkcode,"221 ");
if(strncmp(mailcode,chkcode,3)==0)
printf("Mail Server is disconnecting.\r\n");
// Ensure that socket is inactive
count=0;
bit_clear(PIR1,TMR1IF);	// clear interrupt flag
while(0x40!=(ReadSeiko(0x22) & 0x40))
{
if(bit_test(PIR1,TMR1IF))
{
count++;
bit_clear(PIR1,TMR1IF);	// clear interrupt flag
}
}
// Close Socket
printf("\n\rClosing socket\n\r");
WriteSeiko(Socket_Activate,0);	// close the socket
WriteSeiko(TCP_Data_Send,0);
// Wait for Socket To Close, 2.5 seconds Max, can shorten in most
//cases if we've waited for the buffer to empty above.
delay_ms(2500);
while(ReadSeiko(Socket_Status_H));
delay_ms(5000); // wait five more seconds to be sure socket is closed
// Hang Up Modem by reseting everything
WriteSeiko(Serial_Port_Config,0x06); // TURN OFF DTR AND RTS
delay_ms(10);
RESET = 0;
delay_ms(1);
RESET = 1;
/******************************************************
* ABSOLUTE RESET VECTOR TO LOCATION 0X0000 *
******************************************************/
#asm
MOVLW 0x00
MOVWF 0x0A
GOTO 0x00
#endasm
}
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ