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

#include "16f877 #include "16f877.h"
#include "f877.h"
#include "s7600.h"
#include <ctype.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#define hi(x) (*(&x+1))
 
#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)
#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 1024
#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
short negtemp;
char i,j,ch,addr,temp,pot,ftmp,ctmp,count,count1,page;
long index, byt_cnt, hits;
char Login[10];
char MyIPAddr[4];
char user[33];
char pass[33];
char phone[17];
char read_data[5];
char test_str[7];
char read_Q[7];
char mins[3];
char hours[3];
char day[2];
char date[3];
char month[3];
char year[3];
#include "seiko_ct.c" // Seiko routines use code from AN732
/**************************************************************
** char DataAvailable(void) **
** Determines if there is any data available to read out of **
** the S-7600A. **
** Returns the value of the data available bit from the **
** S-7600A. **
**************************************************************/
char DataAvailable(void)
{
return (ReadSeiko(Serial_Port_Config)&0x80);
}
/**************************************************************
** void S_Putc(char data) **
** Writes a byte of data to the serial port on the S-7600A. **
**************************************************************/
void S_Putc(char data)
{
while(!BUSY);
CS = 1;
RS = 0;
WRITEX = 0;
PORTD = Serial_Port_Data;
TRISD = 0;
READX = 1;
READX = 0;
WRITEX = 1;
RS = 1;
CS = 0;
CS = 1;
WRITEX = 0;
PORTD = data;
READX = 1;
READX = 0;
WRITEX = 1;
CS = 0;
TRISD = 0xff;
}
 
/**************************************************************
** void W_Putc(char data) **
** Writes a byte of data to the socket on the S-7600A. **
**************************************************************/
void W_Putc(char data)
{
// Make sure that the socket buffer is not full
while(0x20==(ReadSeiko(0x22)&0x20))
{
WriteSeiko(TCP_Data_Send,0);
while(ReadSeiko(Socket_Status_H));
}
while(!BUSY);
CS = 1;
RS = 0;
WRITEX = 0;
PORTD = Socket_Data;
TRISD = 0;
READX = 1;
READX = 0;
WRITEX = 1;
RS = 1;
CS = 0;
CS = 1;
WRITEX = 0;
PORTD = data;
READX = 1;
READX = 0;
WRITEX = 1;
CS = 0;
TRISD = 0xff;
}
#include "eeprom.c" // external serial EEPROM routines from AN732
 
/**************************************************************
** void Get_username(void) **
** Requests and reads the user name from the input terminal.**
**************************************************************/
void Get_username(void)
{
char n_tmp;
i=0;
printf("%c[2J",esc);
printf("%c[12;20H 32 chars max",esc);
printf("%c[10;20H Enter user name: ",esc);
while(1)
{
user[i]=0;
ch=GETC();
if(ch==0x0D)
break;
putc(ch);
if(ch != 0x08)
{
user[i]=ch;
i++;
}
if(i==32) break;
}
// write user name to the EEPROM
n_tmp=0;
for(i=0;i<0x1F;i++)
{
ch=user[i];
write_ext_eeprom(n_tmp, user[i]);
n_tmp++;
}
}
 
/**************************************************************
** void Get_password(void) **
** Requests and reads the password from the input terminal. **
**************************************************************/
void Get_password()
{
byte a_tmp;
i=0;
printf("%c[2J",esc);
printf("%c[12;20H 32 chars max",esc);
printf("%c[10;20H Enter password: ",esc);
while(1)
{
pass[i]=0;
ch=getc();
if(ch==0x0D)
break;
if(ch != 0x0A)
{
putc(ch);
if(ch != 0x08)
{
pass[i]=ch;
i++;
}
}
if(i==16) break;
}
// write password to the EEPROM
a_tmp=0x20;
for(i=0;i<0x1F;i++)
{
ch=pass[i];
write_ext_eeprom(a_tmp, pass[i]);
a_tmp++;
}
}
 
/**************************************************************
** void Get_phone(void) **
** Requests and reads the telephone number from the input **
** terminal. **
**************************************************************/
void Get_phone()
{
byte p_tmp;
printf("%c[2J",esc);
printf("%c[12;20H 16 chars max",esc);
printf("%c[10;20H Enter phone number: ",esc);
i=0;
while(1)
{
phone[i]=0;
ch=getc();
if(ch==0x0D)
break;
if(ch != 0x0A)
{
putc(ch);
if(ch != 0x08)
{
phone[i]=ch;
i++;
}
}
if(i==16) break;
}
// write phone number to the EEPROM
p_tmp=0x40;
for(i=0; i<16; i++)
{
ch=phone[i];
write_ext_eeprom(p_tmp, phone[i]);
p_tmp++;
}
}
/**************************************************************
** void Get_Time(void) **
** Resets time and date **
** **
**************************************************************/
void Get_Time(void){
tryminsagain:
printf("%c[2J",esc);
printf("%c[10;20H Enter minutes 00-59: ",esc);
i=0;
while(1)
{
mins[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
{
mins[i]=ch;
i++;
}
else
goto tryminsagain;
if (i==2)
break;
}
if(mins[0] > 0x35)
goto tryminsagain;
swap(mins[0]);
mins[0] &= 0xF0;
mins[1] &= 0x0F;
mins[2] = mins[0] | mins[1];
tryhoursagain:
printf("%c[11;20H Enter hours 00-23: ",esc);
i=0;
while(1)
{
hours[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
{
hours[i]=ch;
i++;
}
else
goto tryhoursagain;
if (i==2)
break;
}
if(hours[0] == 0x32 && hours[1] > 0x33)
goto tryhoursagain;
if(hours[0] > 0x32)
goto tryhoursagain;
swap(hours[0]);
hours[0] &= 0xF0;
hours[1] &= 0x0F;
hours[2] = hours[0] | hours[1];
trydayagain:
printf("%c[12;20H Enter day 1-7 (Sunday = 1): ",esc);
i=0;
while(1)
{
day[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
day[i]=ch;
else
goto trydayagain;
break;
}
if(day[0] > 0x37)
goto trydayagain;
day[0] = day[0] & 0x0F;
trydateagain:
printf("%c[13;20H Enter Date 01-31: ",esc);
i=0;
while(1)
{
date[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
{
date[i]=ch;
i++;
}
else
goto trydateagain;
if (i==2)
break;
}
if(date[0] > 0x33)
goto trydateagain;
if(date[0] == 0x00 && date[1] == 0x00)
goto trydateagain;
if(date[0] == 0x33 && date[1] > 0x31)
goto trydateagain;
swap(date[0]);
date[0] &= 0xF0;
date[1] &= 0x0F;
date[2] = date[0] | date[1];
trymonthagain:
printf("%c[14;20H Enter Month 01-12: ",esc);
i=0;
while(1)
{
month[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
{
month[i]=ch;
i++;
}
else
goto trymonthagain;
if (i==2)
break;
}
if(month[0] > 0x31)
goto trymonthagain;
if(month[0] == 0x00 && month[1] == 0x00)
goto trymonthagain;
if(month[0] == 0x31 && month[1] > 0x32)
goto trymonthagain;
swap(month[0]);
month[0] &= 0xF0;
month[1] &= 0x0F;
month[2] = month[0] | month[1];
tryyearagain:
printf("%c[15;20H Enter Year 00-99: ",esc);
i=0;
while(1)
{
year[i]=0;
ch=getc();
putc(ch);
if(ch < 0x3A && ch > 0x2F)
{
year[i]=ch;
i++;
}
else
goto tryyearagain;
if (i==2)
break;
}
swap(year[0]);
year[0] &= 0xF0;
year[1] &= 0x0F;
year[2] = year[0] | year[1];
i2c_start();
i2c_write(0x9E);
i2c_write(0xC0);
i2c_write(0x00);
i2c_write(0x00); // set seconds to 00
i2c_write(mins[2]); // set minutes
i2c_write(hours[2]); // set hours
i2c_write(day[0]); // set day
i2c_write(date[2]); // set date
i2c_write(month[2]); // set month
i2c_write(year[2]); // set year
i2c_stop();
}
/**************************************************************
** void Read_file(void) **
** Requests and reads the HTML web page that is sent when **
** requested by a web browser. **
** This routine strips out all carriage returns and line- **
** feeds found in the file. It also lookds for a semi- **
** colon to end the file. **
**************************************************************/
void Read_file()
{
printf("%c[2J",esc); // Print request to the terminal
printf("%c[10;20H Ready to receive file",esc);
printf("%c[12;20H 32688 bytes max",esc);
printf("%c[14;20H End file with ;",esc);
printf("%c[16;20H Set your terminal for Hardware Flow Control",esc);
ch=1;
i=0;
index=0x50;
while(1)
{
CTS = 0;
ch=getc();
CTS = 1;
if(index == 32767)
break;
if(ch==00)
break;
if(ch==';')
break;
// Otherwise write character to EEPROM
write_ext_eeprom(index, ch);
index++;
}
write_ext_eeprom(index, 0); // Write terminating NULL
CTS = 0;
// Print status of download to EEPROM
index = index - 80;
printf("%c[2J",esc);
printf("%c[12;28H Received %lu bytes",esc,index);
if(index > 32688)
printf("%c[18:20H Error maximum bytes is 32688",esc);
printf("%c[18;25H Press any key to continue",esc);
ch=getc();
CTS = 1;
}
 
/**************************************************************
** void init_temp **
** initialize the DS1629 **
** **
**************************************************************/
void init_temp(){
i2c_start();
i2c_write(0x9E);
i2c_write(0xAC);
i2c_write(0x00);
i2c_stop();
}
/**************************************************************
** void Menu(void) **
** Displays menu on user's terminal screen. Allows changes **
** to username, password, phone number and web page. **
**************************************************************/
void Menu(void)
{
i=0;
while(ch != 0x1B)
{
CTS=0;
printf("%c[2J",esc);
printf("%c[6;25H 1 Enter user name",esc);
printf("%c[8;25H 2 Enter password",esc);
printf("%c[10;25H 3 Enter phone number",esc);
printf("%c[12;25H 4 Set Time and Date",esc);
printf("%c[14;25H 5 Down load HTML file",esc);
printf("%c[17;30H ESC exit",esc);
ch=getc(); // Get input and process
switch(ch)
{
case 0x31: // '1' -> change username
Get_username();
break;
case 0x32: // '2' -> change password
Get_password();
break;
case 0x33: // '3' -> change phone #
Get_phone();
break;
case 0x34: // '4' -> change time and date
Get_Time();
break;
case 0x35: // '5' -> new web page
Read_file();
break;
}
}
CTS=1;
}
 
 
 
/**************************************************************
** 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 LED1
// 1 LED2
PORTE = 0xFA; //11111010
TRISA = 0xD1; //11010001
TRISB = 0x18; //00011000
TRISC = 0x80; //10000000
TRISD = 0xFF; //11111111
TRISE = 0x00; //00000000
ADCON1 = 0x06; //00000110 all digital
ADCON0 = 0;
T1CON = 0x31; //00110001 Timer1
CTS = 1;
init_ext_eeprom();
init_temp();
Menu();
restart:
RESET = 0;
WriteSeiko(Serial_Port_Config,0x06);
delay_ms(10);
RESET = 1;
 
WriteSeiko(Clock_Div_L,0xE5);
while(ReadSeiko(Clock_Div_L) != 0xE5)
WriteSeiko(Clock_Div_L,0xE5);
WriteSeiko(Clock_Div_H,0x00);
 
WriteSeiko(BAUD_Rate_Div_L,0x5F);
WriteSeiko(BAUD_Rate_Div_H,0x00);
 
WriteSeiko(Serial_Port_Config,0x00);
printf(S_Putc,"AT&F\r");
delay_ms(10);
WriteSeiko(PPP_Control_Status,0x01);
WriteSeiko(PPP_Control_Status,0x00);
WriteSeiko(PPP_Control_Status,0x20);
delay_ms(5);
 
ch=1;
i=0;
while(ch)
{
ch = read_ext_eeprom(i);
i++;
}
i--;
WriteSeiko(PAP_String,i);
for(j=0; j<i; j++)
{
ch = read_ext_eeprom(j);
WriteSeiko(PAP_String,ch);
}
 
ch=1;
i=0x20;
while(ch)
{
ch = read_ext_eeprom(i);
i++;
}
i--;
i=(i-0x20);
WriteSeiko(PAP_String,i);
for(j=0x20; j<(i + 0x20); j++)
{
ch = read_ext_eeprom(j);
WriteSeiko(PAP_String,ch);
}
WriteSeiko(PAP_String,0x00);
printf(S_Putc,"ATDT");
ch=1;
index=0x40;
while(1)
{
ch = read_ext_eeprom(index);
if(ch == 0)
break;
S_Putc(ch);
index++;
}
printf(S_Putc,"\r");
delay_ms(5);
printf("%c[2J",esc);
printf("\rDialing ");
ch=1;
i=0x40;
while(1)
{
ch = read_ext_eeprom(i);
if(ch == 0)
break;
printf("%c",ch);
i++;
}
printf("\r");
delay_ms(20000);
WriteSeiko(PPP_Control_Status,0x62);
WriteSeiko(Serial_Port_Config,0x01);
delay_ms(5);
 
while(!(ReadSeiko(PPP_Control_Status)&0x01))
delay_ms(5);
while(ReadSeiko(Our_IP_Address_L) == 0);
MyIPAddr[0] = ReadSeiko(Our_IP_Address_L);
MyIPAddr[1] = ReadSeiko(Our_IP_Address_M);
MyIPAddr[2] = ReadSeiko(Our_IP_Address_H);
MyIPAddr[3] = ReadSeiko(Our_IP_Address_U);
 
 
printf("\r\nMy address is %u.%u.%u.%u",MyIPAddr[3],MyIPAddr[2],MyIPAddr[1],MyIPAddr[0]);
 
while(1)
{
while(1)
{
delay_ms(1);
if(!(ReadSeiko(PPP_Control_Status)&0x01))
goto restart;
if(ReadSeiko(Serial_Port_Config)&0x40)
goto restart;
WriteSeiko(Socket_Index,0x00);
WriteSeiko(Socket_Config_Status_L,0x10);
delay_ms(10);
WriteSeiko(Our_Port_L,80);
WriteSeiko(Our_Port_H,0);
 
WriteSeiko(Socket_Config_Status_L,0x06);
 
WriteSeiko(Socket_Activate,0x01);
delay_ms(5);
 
printf("\n\rSocket open\n\r");
i = 2;
while(1)
{
delay_ms(1);
if(!(ReadSeiko(PPP_Control_Status)&0x01))
goto restart;
if(ReadSeiko(Serial_Port_Config)&0x40)
goto restart;
 
temp = ReadSeiko(Socket_Status_M);
if(temp&0x10)
{
i = 0;
break;
}
else if(temp&0xe0)
break;
if(temp == 0x09)
continue;
delay_ms(5);
i++;
if(i == 255)
break;
}
if(!i)
break;
}
if(i == 1)
break;
printf("\n\rWaiting for data");
WriteSeiko(Socket_Interrupt_H,0xf0);
i=0;
 
printf("\n\rReading data\r\n");
while(ReadSeiko(Socket_Config_Status_L)&0x10)
{
temp = ReadSeiko(Socket_Data);
putc(temp);
}
 
WriteSeiko(Socket_Data,0X0A);
WriteSeiko(Socket_Data,0X0D);
WriteSeiko(Socket_Data,0X0A);
WriteSeiko(Socket_Data,0X0D);
 
byt_cnt=0;
index=0x50;
ch=1;
while(ch != 0)
{
ch = read_ext_eeprom(index);
if(ch == 0)
break;
if(ch == 0x25)
{
index++;
ch = read_ext_eeprom(index);
switch(ch)
{
case 'a':
printf(W_putc,"%u.%u.%u.%u",MyIPAddr[3],MyIPAddr[2],MyIPAddr[1],MyIPAddr[0]);
break;
case 'c':
i2c_start();
i2c_write(0x9E);
i2c_write(0xEE);
delay_ms(500);
i2c_start();
i2c_write(0x9E);
i2c_write(0xAA);
i2c_start();
i2c_write(0x9F);
ctmp = i2c_read();
i2c_stop();
negtemp = FALSE;
if(ctmp >= 0x80){
ctmp = !ctmp +1;
negtemp = TRUE;
}
if(negtemp==TRUE)
printf(W_putc,"-");
printf(W_putc,"%u",ctmp);
break;
case 't':
i2c_start();
i2c_write(0x9E);
i2c_write(0xC0);
i2c_write(0x01);
i2c_start();
i2c_write(0x9F);
//i = i2c_read();
mins[0] = i2c_read();
hours[0] = i2c_read();
day[0] = i2c_read();
date[0] = i2c_read();
month[0] = i2c_read();
year[0] = i2c_read();
i2c_stop();
negtemp = FALSE;
if(ctmp >= 0x80){
ctmp = !ctmp +1;
negtemp = TRUE;
}
//secs[2] = secs[0];
//secs[0] &= 0xF0;
//secs[0] >>= 4;
//secs[0] &= 0x0F;
//secs[0] += 0x30;
//secs[1] = secs[2];
//secs[1] &= 0x0F;
//secs[1] += 0x30;
mins[2] = mins[0];
mins[0] &= 0xF0;
mins[0] >>= 4;
mins[0] &= 0x0F;
mins[0] += 0x30;
mins[1] = mins[2];
mins[1] &= 0x0F;
mins[1] += 0x30;
 
hours[2] = hours[0];
hours[0] &= 0xF0;
hours[0] >>= 4;
hours[0] &= 0x0F;
hours[0] += 0x30;
hours[1] = hours[2];
hours[1] &= 0x0F;
hours[1] += 0x30;
//day[0] &= 0x0F;
//day[0] += 0x30;
date[2] = date[0];
date[0] &= 0xF0;
date[0] >>= 4;
date[0] &= 0x0F;
date[0] += 0x30;
date[1] = date[2];
date[1] &= 0x0F;
date[1] += 0x30;
month[2] = month[0];
month[0] &= 0xF0;
month[0] >>= 4;
month[0] &= 0x0F;
month[0] += 0x30;
month[1] = month[2];
month[1] &= 0x0F;
month[1] += 0x30;
year[2] = year[0];
year[0] &= 0xF0;
year[0] >>= 4;
year[0] &= 0x0F;
year[0] += 0x30;
year[1] = year[2];
year[1] &= 0x0F;
year[1] += 0x30;
printf(W_putc,"%c%c:%c%c %c%c-%c%c-20%c%c",hours[0],hours[1],mins[0],mins[1],month[0],month[1],date[0],date[1],year[0],year[1]);
break;
}
}
else
{
count=0;
count1=0;
bit_clear(PIR1,TMR1IF);
while(0x20==(ReadSeiko(0x22)&0x20))
{
WriteSeiko(TCP_Data_Send,0);
while(ReadSeiko(Socket_Status_H));
{
if(ReadSeiko(Serial_Port_Config)&0x40)
goto restart;
if(bit_test(PIR1,TMR1IF))
{
count++;
if(count > 0xf8)
{
count1++;
count=0;
}
if(count1 > 0xC0)
goto restart;
bit_clear(PIR1,TMR1IF);
}
}
WriteSeiko(Socket_Data,ch);
}
index++;
}
 
WriteSeiko(TCP_Data_Send,0);
 
count=0;
bit_clear(PIR1,TMR1IF);
while(0x40!=(ReadSeiko(0x22) & 0x40))
{
if(bit_test(PIR1,TMR1IF))
{
count++;
bit_clear(PIR1,TMR1IF);
}
}
 
printf("close socket\n");
WriteSeiko(Socket_Activate,0);
WriteSeiko(TCP_Data_Send,0);
 
for(i=0;i<255;i++)
{
delay_ms(10);
temp = ReadSeiko(Socket_Status_M);
if((temp & 0x0f)==0x08)
break;
if((temp&0xe0))
break;
}
printf("\n\rfinal socket wait\n");
while(ReadSeiko(Socket_Status_H));
delay_ms(5000);
}
}
}
Click here to get your listing up.

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