|
|
View previous topic :: View next topic |
Author |
Message |
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max6675 |
Posted: Sat Dec 02, 2017 6:48 am |
|
|
hi Ttelmah,
Here there is no option for using hardware spi. I want to use the software spi only. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19619
|
|
Posted: Sat Dec 02, 2017 8:22 am |
|
|
I have to ask 'why'?. Given you are on the hardware pins, seems silly not to use the hardware....
However I have already given you what can be a a software solution:
Code: |
#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, MODE=0, BITS=16, FORCE_SW, STREAM=SPI_1)
//Then use no other setup or read commands.
//Just use:
unsigned int16 value; //any suitable 16bit variable
output_low(MAX_CS);
value=spi_xfer(SPI_1, 0L); //transfer the value
output_high(MAX_CS);
|
With 'FORCE_SW', this generates software SPI. Transfers 16bits. By default it'll work as fast as possible, but just specify a baud rate if it is too fast. |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max6675 |
Posted: Sun Dec 03, 2017 11:56 pm |
|
|
hi Ttelmah,
There is the change in hardware spi. The sdo is using as sdi. For that only using software spi. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19619
|
|
Posted: Mon Dec 04, 2017 7:21 am |
|
|
So use the software as shown.
#USE SPI supports both hardware and software SPI. |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
|
Posted: Fri Dec 08, 2017 7:35 am |
|
|
hi Ttelmah,
i use software spi program. i got it as 00.0 in the 7 segment display
Code: | #include <16F72.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#use delay(clock=20000000)
#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4,ENABLE=PIN_C6, MODE=0, BITS=16, STREAM=SPI_1, MSB_FIRST)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
delay_cycles(1);
data=spi_xfer(SPI_1, 0L); //transfer the value
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3)); //returns only the bits converning temperature
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4); //adjusts data to floating point format, and accounts for the decimal point
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(10);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
|
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max6675 |
Posted: Fri Dec 08, 2017 7:40 am |
|
|
hi,
I've written the software spi program for max6675. But i got as 65.0 as output in 7 segment display. not changing the values . please help us to resolve
Code: |
#include <16F72.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#use delay(clock=20000000)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
for (i = 0; i<16; i++) {
delay_cycles(1);
output_high(MAX_CLK);
delay_cycles(1);
output_low(MAX_CLK);
shift_left(&data,2,input(MAX_DO));
}
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3));
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4);
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(20);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(20);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(20);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19619
|
|
Posted: Fri Dec 08, 2017 7:47 am |
|
|
Use the compiler SPI. I've already posted how to do this. The form I show generates software SPI. Use it.
Your software SPI is _not_ doing the timings correctly. Mode0, should read the data after the rising edge of the clock. You are reading it at the point where it will be changing..... |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max6675 |
Posted: Fri Dec 08, 2017 8:04 am |
|
|
hi
I already written as you given for sample. but i got only 00.0 only for this code.
Code: |
#include <16F72.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#use delay(clock=20000000)
#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4,ENABLE=PIN_C6, MODE=0, BITS=16, STREAM=SPI_1, MSB_FIRST)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
delay_cycles(1);
data=spi_xfer(SPI_1, 0L); //transfer the value
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3)); //returns only the bits converning temperature
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4); //adjusts data to floating point format, and accounts for the decimal point
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(10);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9295 Location: Greensville,Ontario
|
|
Posted: Fri Dec 08, 2017 8:19 am |
|
|
You really need to break up your program into 2 parts or functions
1) data acquistion (reading the SPI device), number=get_data()
2) displaying the data, a function, dsp_data(number)
Do #2 first. Confirm, using a simple loop that the display actually displays the numbers 000 to 999 properly. This loop should have a 1/2 second cycle time so you can read each number.
Until you can confirm the 'display' function works do not try to read the SPI device. You need to KNOW the display works 100%.
Jay |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max6675 |
Posted: Fri Dec 08, 2017 8:48 am |
|
|
hi jay,
The display working 100%. There is also the increment counter module in the same board, it works correctly.
In the program there is separate function for data acquisition. I need to break the display function in the code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9295 Location: Greensville,Ontario
|
|
Posted: Fri Dec 08, 2017 9:05 am |
|
|
OK, since the display section works fine, then I suspect the SPI 'mode' may be wrong. Simply read the device datasheet, confirm which mode (there are 4), then see what your program is set for. I'd dump the listing to confirm the PIC's mode is being set correctly. While rare, there may be a compiler 'bug' not properly setting the bits properly. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 08, 2017 1:00 pm |
|
|
temtronic,
The spi mode was already discussed on page 1 of this thread.
It's mode 0.
madhusuthanan,
1. Post a list of the connections between the PIC and the Max6675.
Don't post the pin names. Post the pin numbers. Use an ohmmeter
to verify the connections. Then post the list of connections between
the two chips. Example:
Code: |
16F72 Max6675
14 to 5
.
.
.
etc.
|
2. What package are you using for the 16F72 ?
3. Do you actually have a thermocouple connected to the T+ and T-
pins on the Max6675 ? Did you follow the schematic on page 1 of the
Max6675 data sheet ? Are you using a "Type K" thermocouple ?
Did you connect the Chromel lead to T+, and the Alumel lead to T-,
as said in the Max6675 data sheet ?
4. Is this a Proteus project, or is it real hardware ? |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
max 6675 |
Posted: Sat Dec 09, 2017 4:00 am |
|
|
hi
the pin numbers are connected between pic & max6675 module
16f72 max6675 module
14 3
16 5
17 4
vcc 2
gnd 1
max6675 module
[img]
http://lantis.co.za/ocols/image/cache/data/MAX6675%20Thermocouple%20Temperature%20Sensor%20Module%20Type%20K%20SPI%20Interface-700x700.jpg
[/img]
pic package
[img]
http://lh3.ggpht.com/-lUX1VE6vqV4/T2S0I1lXynI/AAAAAAAAErs/zPKdIEsRlkQ/image_thumb%25255B20%25255D.png?imgmax=800
[/img]
it is real hardware.
I connected red to T+ & blue to T-
these are the details of the max6675 & pic
I had written code for this module
this program shows the only 00.0 as output
Code: |
#include <16F72.h>
#device adc=8
#FUSES NOWDT
#FUSES HS
#FUSES NOPUT
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#use delay(clock=20000000)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
data=spi_xfer(SPI_1, 0L); //transfer the value
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3));
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4);
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(10);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
the another program
this show value 65.0 only
Code: |
#include <16F72.h>
#device adc=8
#FUSES NOWDT
#FUSES HS
#FUSES NOPUT
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#use delay(clock=20000000)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
for (i = 0; i<16; i++) {
delay_cycles(1);
output_high(MAX_CLK);
delay_cycles(1);
output_low(MAX_CLK);
shift_left(&data,2,input(MAX_DO));
}
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3));
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4);
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(20);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(20);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(20);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
please guide me to resolve this problem |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19619
|
|
Posted: Sat Dec 09, 2017 5:08 am |
|
|
You _must_ have the #USE SPI line to setup the SPI.
You are using spi_xfer without setting it up... |
|
|
madhusuthanan
Joined: 23 Aug 2017 Posts: 15
|
|
Posted: Sat Dec 09, 2017 5:25 am |
|
|
hi Ttelmah,
it is there i forget to copy the line here is the code.
Code: |
#include <16F72.h>
#device adc=8
#FUSES NOWDT
#FUSES HS
#FUSES NOPUT
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4, ENABLE=PIN_C6, MODE=0, BITS=16, STREAM=spitemp, MSB_FIRST)
#use delay(clock=20000000)
#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3
int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
output_low(MAX_CLK);
output_low(MAX_CS);
delay_cycles(1);
output_high(MAX_CS);
}
int16 read_TC(void)
{
int datah, datal=0;
int16 data=0;
int i;
output_low(MAX_CS);
data=spi_xfer(SPI_1, 0L); //transfer the value
thermocouple_error = bit_test(data,2);
delay_cycles(1);
output_high(MAX_CS);
return(data);
}
int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3));
}
int16 toCalc_TC(int16 tmp)
{
return((int16)tmp * 10/4);
}
int16 do_everything(void)
{
return(toCalc_TC(sortout(read_TC())));
}
unsigned int Hex(int a) {
switch(a) {
case 1: return 0x06;
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
case 0: return 0x3F;
case 'e': return 0x79;
case 'r': return 0x70;
}
}
void main()
{
int16 value;
unsigned long Temp;
char error[] = "err";
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //52.4 ms overflow
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(GLOBAL);
set_timer0(0);
set_timer1(0);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
init_TC();
while(1) {
if (input(pin_A4)) {
value = do_everything();
if (!(thermocouple_error)) {
Temp = value;
output_b(Hex(Temp %10));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b((Hex((Temp/10) %10)) | 0x80);
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(10);
output_b(Hex((Temp/100) %10));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(10);
}
else {
output_b(Hex(error[0]));
output_low (pin_c2);
output_high (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[1]));
output_high (pin_c2);
output_low (pin_c1);
output_high (pin_c0);
delay_ms(8);
output_b(Hex(error[2]));
output_high (pin_c2);
output_high (pin_c1);
output_low (pin_c0);
delay_ms(8);
}
}
}
}
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|