GrandAlf
Advanced Member level 2
rtx51tny, watchdog
I have a bit of a problem, the following code works fine, but when I try to make a function out of the contents of the functions block, it compiles, but will not run.
Made a file called CancelCall.C
Added contents of the block marked FUNCTIONS
Included At898252,Delay and lcd Headers
Made file CancelCall.H
Added
Extern void CancelCall(void);
Added CancelCall.h to main file.
Compiles OK, but will not run. Still learning C, and have probably done something stupid. Any help greatly appreciated.
Sorry about taking up so much bandwidth.
=============================================
#include <AT898252.h>
#include <rtx51tny.h>
#include "lcd.h"
#include <stdio.h>
#include "delay.h"
// Bit Outputs
sbit led = P1^7;
sbit C1 = P2^6;
sbit C2 = P2^5;
sbit C3 = P2^4;
sbit Sounder = P3^2;
sbit BusyOp = P3^3;
sbit Tone = P3^4;
sbit Release = P3^5;
sbit AudVid = P3^6;
sbit Strobe = P3^7;
// Bit Inputs Active Low
sbit PTE = P2^7;
sbit TradeClock = P1^6;
sbit Privacy = P1^7;
sbit OpenDoor = P3^0;
sbit BusyIp = P3^1;
// Variables
unsigned char DialNumber , KeyRead;
unsigned int ActualNumber;
unsigned char Address;
unsigned char Loop;
char buf[8];
//FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
void CancelCall(void) // Resets All Junction Boxes
{
unsigned char Address;
Strobe = 1;
Address = 0;
Tone = 0;
lcd_goto(0);
lcd_puts("END- Please Wait");
AudVid = 0; BusyOp = 1;
DelayMs(200);
Strobe = 0; DelayUs(50); Strobe = 1;
DelayMs(50);
while (Address < 255){
P0 = Address;
Strobe = 0; DelayUs(50); Strobe = 1;
DelayMs(20);
Address ++ ; }
lcd_goto(0);
lcd_puts("Dial Number ");
}
//////////////////////////////////////////////////////////////////////////////
job0 () _task_ 0 { // Main Startup Task
os_create_task (1); // Starts Ticker Routine + RTE
lcd_init();
DialNumber = 0;
KeyRead = 0;
ActualNumber = 0;
Sounder = 0;
CancelCall();
while (1) {
led = 0;
DelayMs (200);
led = 1;
DelayMs (200);
C1=0; C2=0; C3=0;
while ((P2 & 0x0F) == 0x0F) {} // Waits for Key Press
C1 = 0; C2 = 1; C3 = 1;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 1;
if (KeyRead == 13) DialNumber = 4;
if (KeyRead == 11) DialNumber = 7;
if (KeyRead == 7) // Reset
{
DialNumber = 0;
KeyRead = 0;
ActualNumber = 0;
C1 = 1; C2 = 1; C3 = 1;
lcd_goto(0);
lcd_puts("Dial Number ");
}
C1 = 1; C2 = 0; C3 = 1;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 2;
if (KeyRead == 13) DialNumber = 5;
if (KeyRead == 11) DialNumber = 8;
if (KeyRead == 7) DialNumber = 0;
C1 = 1; C2 = 1; C3 = 0;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 3;
if (KeyRead == 13) DialNumber = 6;
if (KeyRead == 11) DialNumber = 9;
if (KeyRead == 7) { // Call Key this bit is wrong, should be call not cancel
ActualNumber = 0;
DialNumber = 0;
KeyRead = 0;
CancelCall(); }
ActualNumber = (ActualNumber * 10) + DialNumber;
if (ActualNumber > 0) {
lcd_clear();
lcd_puts("Dialling ");
lcd_goto(0x09);
sprintf(buf,"%d",ActualNumber);
lcd_puts(buf); }
C1 = 0; C2 = 0 ; C3 = 0;
while ((P2 & 0x0F) != 0x0F) {} // Waits for Key Release
os_wait (K_TMO,5,0); } }
//=====================================================
// Checks PTE and Opens Door Also Pulses Ext Watchdog
job1 () _task_ 1 {
Loop = 0; Release = 0;
while (1) {
while (PTE == 1) {
Sounder = 0; DelayMs(50); Sounder = 1; DelayMs(50); Sounder = 0;//change to 1 ms
os_wait (K_TMO,30,0); }
//needs sound statement here, when written
while (Loop <20) {
Release = 1;
Sounder = 0; DelayMs(50); Sounder = 1; DelayMs(50); Sounder = 0;//change to 1 ms
DelayMs(255);
Loop++; }
Loop = 0; Release = 0; } }
//=====================================================
I have a bit of a problem, the following code works fine, but when I try to make a function out of the contents of the functions block, it compiles, but will not run.
Made a file called CancelCall.C
Added contents of the block marked FUNCTIONS
Included At898252,Delay and lcd Headers
Made file CancelCall.H
Added
Extern void CancelCall(void);
Added CancelCall.h to main file.
Compiles OK, but will not run. Still learning C, and have probably done something stupid. Any help greatly appreciated.
Sorry about taking up so much bandwidth.
=============================================
#include <AT898252.h>
#include <rtx51tny.h>
#include "lcd.h"
#include <stdio.h>
#include "delay.h"
// Bit Outputs
sbit led = P1^7;
sbit C1 = P2^6;
sbit C2 = P2^5;
sbit C3 = P2^4;
sbit Sounder = P3^2;
sbit BusyOp = P3^3;
sbit Tone = P3^4;
sbit Release = P3^5;
sbit AudVid = P3^6;
sbit Strobe = P3^7;
// Bit Inputs Active Low
sbit PTE = P2^7;
sbit TradeClock = P1^6;
sbit Privacy = P1^7;
sbit OpenDoor = P3^0;
sbit BusyIp = P3^1;
// Variables
unsigned char DialNumber , KeyRead;
unsigned int ActualNumber;
unsigned char Address;
unsigned char Loop;
char buf[8];
//FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
void CancelCall(void) // Resets All Junction Boxes
{
unsigned char Address;
Strobe = 1;
Address = 0;
Tone = 0;
lcd_goto(0);
lcd_puts("END- Please Wait");
AudVid = 0; BusyOp = 1;
DelayMs(200);
Strobe = 0; DelayUs(50); Strobe = 1;
DelayMs(50);
while (Address < 255){
P0 = Address;
Strobe = 0; DelayUs(50); Strobe = 1;
DelayMs(20);
Address ++ ; }
lcd_goto(0);
lcd_puts("Dial Number ");
}
//////////////////////////////////////////////////////////////////////////////
job0 () _task_ 0 { // Main Startup Task
os_create_task (1); // Starts Ticker Routine + RTE
lcd_init();
DialNumber = 0;
KeyRead = 0;
ActualNumber = 0;
Sounder = 0;
CancelCall();
while (1) {
led = 0;
DelayMs (200);
led = 1;
DelayMs (200);
C1=0; C2=0; C3=0;
while ((P2 & 0x0F) == 0x0F) {} // Waits for Key Press
C1 = 0; C2 = 1; C3 = 1;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 1;
if (KeyRead == 13) DialNumber = 4;
if (KeyRead == 11) DialNumber = 7;
if (KeyRead == 7) // Reset
{
DialNumber = 0;
KeyRead = 0;
ActualNumber = 0;
C1 = 1; C2 = 1; C3 = 1;
lcd_goto(0);
lcd_puts("Dial Number ");
}
C1 = 1; C2 = 0; C3 = 1;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 2;
if (KeyRead == 13) DialNumber = 5;
if (KeyRead == 11) DialNumber = 8;
if (KeyRead == 7) DialNumber = 0;
C1 = 1; C2 = 1; C3 = 0;
KeyRead = (P2 & 0x0F);
if (KeyRead == 14) DialNumber = 3;
if (KeyRead == 13) DialNumber = 6;
if (KeyRead == 11) DialNumber = 9;
if (KeyRead == 7) { // Call Key this bit is wrong, should be call not cancel
ActualNumber = 0;
DialNumber = 0;
KeyRead = 0;
CancelCall(); }
ActualNumber = (ActualNumber * 10) + DialNumber;
if (ActualNumber > 0) {
lcd_clear();
lcd_puts("Dialling ");
lcd_goto(0x09);
sprintf(buf,"%d",ActualNumber);
lcd_puts(buf); }
C1 = 0; C2 = 0 ; C3 = 0;
while ((P2 & 0x0F) != 0x0F) {} // Waits for Key Release
os_wait (K_TMO,5,0); } }
//=====================================================
// Checks PTE and Opens Door Also Pulses Ext Watchdog
job1 () _task_ 1 {
Loop = 0; Release = 0;
while (1) {
while (PTE == 1) {
Sounder = 0; DelayMs(50); Sounder = 1; DelayMs(50); Sounder = 0;//change to 1 ms
os_wait (K_TMO,30,0); }
//needs sound statement here, when written
while (Loop <20) {
Release = 1;
Sounder = 0; DelayMs(50); Sounder = 1; DelayMs(50); Sounder = 0;//change to 1 ms
DelayMs(255);
Loop++; }
Loop = 0; Release = 0; } }
//=====================================================